2016-12-29 108 views
1

我们在我们公司使用helpedesk软件,它设置为从启用IMAP的邮箱中获取电子邮件。有时候,服务台程序会起作用,并停止拉取消息。该服务和其他指标显示,一切正常,但邮件将开始排队在我们的帮助台邮箱。比较PowerShell输出

因此,我们希望监控邮箱中的项目计数以查看它是否已备份,并且如果发送自动发送电子邮件。

我可以使用此命令查询Office365上的邮箱存储。它返回隐藏物品的数量。在这种情况下,46

Get-MailboxFolderStatistics -Identity [email protected] -FolderScope Inbox | ?{$_.FolderPath -like '/Inbox'} | Select Name, ItemsInFolder 

Name ItemsInFolder 
---- ------------- 
Inbox   46 

我不明白怎么输出,看它是否经过一定的阈值相比,如50一旦超过阈值,我可以采取行动,如发送电子邮件或重新启动问题服务等。

回答

0
# store what you need in a variable 
# -ExpandProperty ensures you only get the value without the property name 
$count = Get-MailboxFolderStatistics -Identity [email protected] -FolderScope Inbox | 
    Where-Object { $_.FolderPath -like "/Inbox" } | 
    Select-Object -ExpandProperty ItemsInFolder 

# compare and alert 
if($count -ge 50) { 
    "50 or more mails in Inbox, send alert mail" 
} 
0

因此,您需要在此处执行的操作非常简单。第一家店,你已经写在一个变量的cmdlet的结果,如$items

$items = Get-MailboxFolderStatistics ... 

随后的$items.itemsinfolder的值进行比较,以你的门槛

if($items.itemsinfolder -gt 50){ 
    send your email, you can access the $items.name property and include it in the body if that is helpful 
}