Outlook 收件箱过滤器不起作用....为什么不呢?
The Outlook Inbox Filter doesn't work....why not?
这不是只显示收件箱项目最近两天的 ReceivedTime,而是显示所有收件箱项目,为什么?
$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)
$DateYest = (Get-Date).AddDays(-2)
$InboxFolder | where-object {$_.ReceivedTime -gt "$DateYest"}
ForEach ($MailItem in $InboxFolder) {
write-host $MailITem.ReceivedTime
}
您发布的代码 return 没有任何收件箱项目。正如所写,您正在过滤您的一个收件箱,因为它不存在 RecievedTime
属性。我的假设是您的示例缺少 .Items
属性。如果您按原样将 .Items
添加到您的过滤器,它不会被捕获到变量或传递到管道,因此它会直接输出到控制台。但是,如果编写得当,过滤器可以正常工作。
$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)
$DateYest = (Get-Date).AddDays(-2)
$filteredItems = $InboxFolder.items | where-object {$_.ReceivedTime -gt $DateYest}
foreach ($MailItem in $filteredItems) {
write-host $MailITem.ReceivedTime
}
或
$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)
$DateYest = (Get-Date).AddDays(-2)
$InboxFolder.items |
Where-Object {$_.ReceivedTime -gt $DateYest} |
ForEach-Object {
write-host $_.ReceivedTime
}
这不是只显示收件箱项目最近两天的 ReceivedTime,而是显示所有收件箱项目,为什么?
$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)
$DateYest = (Get-Date).AddDays(-2)
$InboxFolder | where-object {$_.ReceivedTime -gt "$DateYest"}
ForEach ($MailItem in $InboxFolder) {
write-host $MailITem.ReceivedTime
}
您发布的代码 return 没有任何收件箱项目。正如所写,您正在过滤您的一个收件箱,因为它不存在 RecievedTime
属性。我的假设是您的示例缺少 .Items
属性。如果您按原样将 .Items
添加到您的过滤器,它不会被捕获到变量或传递到管道,因此它会直接输出到控制台。但是,如果编写得当,过滤器可以正常工作。
$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)
$DateYest = (Get-Date).AddDays(-2)
$filteredItems = $InboxFolder.items | where-object {$_.ReceivedTime -gt $DateYest}
foreach ($MailItem in $filteredItems) {
write-host $MailITem.ReceivedTime
}
或
$objOutlook = new-object -comobject Outlook.Application
$namespace = $objOutlook.GetNameSpace("MAPI")
$InboxFolder = $namespace.GetDefaultFolder(6)
$DateYest = (Get-Date).AddDays(-2)
$InboxFolder.items |
Where-Object {$_.ReceivedTime -gt $DateYest} |
ForEach-Object {
write-host $_.ReceivedTime
}