2016-12-29 124 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 
}