$Outlook = New-Object -ComObject Outlook.Application
$OutlookInbox = $Outlook.session.GetDefaultFolder(6)
$TotalEmailCount = $OutlookInbox.ShowItemCount
While ($TotalEmailCount -eq 0)
{
Start-Sleep -s 10
Write-Host "Waiting for the email"
}
Write-Host $TotalEmailCount
最初,收件箱文件夹为空。现在,我试图等到Outlook中收到一封电子邮件,然后在到达时打印一些“文本”。但是,当我尝试运行此代码时,我总是得到的输出为“1”。我正在使用powershell。请帮忙!
最佳答案
ShowItemCount
是要检查的错误属性。该returns an enumerator that defines whether outlook shows a count of unread emails on a folder,当前为您设置为“1”。这是一种设置,而不是电子邮件数量。
我目前没有任何地方可以对此进行测试,但是我认为这是您需要的:
$Outlook = New-Object -ComObject Outlook.Application
$OutlookInbox = $Outlook.session.GetDefaultFolder(6)
$TotalEmailCount = $OutlookInbox.Items.Count
While ($TotalEmailCount -eq 0)
{
Start-Sleep -s 10
Write-Host "Waiting for the email"
$TotalEmailCount = $OutlookInbox.Items.Count
}
Write-Host $TotalEmailCount
请注意(如上所述),您需要在循环中重新检查项目数,否则脚本将永远运行。
关于powershell - 通过Powershell在Outlook中的电子邮件计数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46025584/