1
當我的加載過程失敗時,我沒有收到電子郵件警報,下面是我的腳本。請讓我知道我做錯了,並提出一種方法,使病情工作Powershell腳本無法發送電子郵件警報
$body = Get-Content -Path D:\APPDATA\FDMEE\Scripts\output.txt | Out-String
$fail = Get-Content "D:\APPDATA\FDMEE\Scripts\output.txt" | Select-String "FAILED"
if($fail-eq "$True"){Send-MailMessage -From "[email protected]" -To ""[email protected]""-Subject " Load failed on the Production Server." -Body "$body" -Attachments "D:\APPDATA\FDMEE\Scripts\output.txt" -smtpServer mail.xpioc.com}
Output.txt的內容
process_id : 50836
STATUS : FAILED
RULE_ID : 16
RULE_NAME : INTERNATIONAL
我會補充說,如果不需要'Select-String'的結果對象,那麼您可以使用'-Quiet',以便結果真正是一個布爾值。當然不是必需的。 – Matt
如果($ fail){Send-MailMessage -From「[email protected]」-To「」[email protected]「」 - 主題「生產服務器上的加載失敗」,我修改了腳本 。 -Body「$ body」-Attachments「D:\ APPDATA \ FDMEE \ Scripts \ output.txt」-smtpServer mail.xpioc.com}。 現在我正在收到電子郵件警報,儘管負載運行良好。我相信,如果我錯了,我不應該收到if($ fail)條件的電子郵件警報,更正我。我想,它不會識別字符串。 此output.txt PROCESS_ID:50893 狀態:成功 RULE_ID:16 RULE_NAME:國際 –
馬克沒有'-Quiet'參數SLS的變種'$ fail'will包含'狀態:FAILED'和若永遠是真的,因爲$失敗不是空的 – LotPings