powershell - 通过Powershell在Outlook中的电子邮件计数

标签 powershell outlook

$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/

相关文章:

json - 使用Powershell的另一个循环JSON对象

powershell - 自动保存在 Powershell 中

html - Outlook 忽略了我电子邮件的 CSS,包括字体系列和背景颜色

python - 在 Python 中按特定日期列出 Outlook 电子邮件

outlook - 如何在 Outlook 中启用/禁用我的功能区按钮

sharepoint - 用于列出所有 sharepoint 2010/2007 页面及其布局的 Powershell 脚本

powershell - 为什么不为可选参数分配位置?电源外壳

excel - 将对象粘贴到空单元格/工作表时出现错误 424 未被识别为对象

powershell - 使用 Azure Powershell 或 Azure CLI 创建 Log Analytics 警报

c# - 如何同步等待 'AuthenticationContext.AcquireTokenAsync()'?