使用
Items.Sort("ReceivedTime", false)
,然后使用
Items(1)
.
一定要去商店
Items
变量中的集合,而不是访问
MAPIFolder.Items
多次,否则你会得到一个全新的
项目
每次你这么做的时候都要反对。
编辑:我是这个问题的负责人,我在这里为那些可能和我一样高深莫测的人提供了正确的代码,但他们一开始并没有意识到我在说什么!
# New Outlook object
$ol = new-object -comobject "Outlook.Application";
# MAPI namespace
$mapi = $ol.getnamespace("mapi");
$folder = $mapi.Folders.Item('name@gmail.com').Folders.Item('Inbox')
# Get the items in the folder
$contents = $folder.Items
# Sort the items in the folder by the metadata, in this case ReceivedTime
$contents.Sort("ReceivedTime")
# Get the first item in the sorting; in this case, you will get the oldest item in your inbox.
$item = $contents.GetFirst()
echo $item
# If instead, you wanted to get the newest item, you could do the same thing but do $item = $contents.GetLast()