1
我正在開發一個簡單的解決方案,如果在遠程服務器上停止任何服務,需要發送電子郵件警報。在HTML報告中獲取服務名稱
下面是流量:
- 在一個記事本文件寫我要監控
- PowerShell腳本會從文件中讀取所有服務的所有服務,並檢查其狀態。
- 如果有任何服務停止,它會將內容添加到我的HTML格式併發送一封電子郵件。
一切正常工作正常,但我得到System.ServiceProcess.ServiceController
而不是實際的服務名稱。我在PowerShell控制檯上打印一些東西,然後在那裏獲取服務名稱。
代碼:
$Services = Get-Content D:\Services.txt
foreach ($Service in $Services) {
Write-Host "Service Name: "$Service
}
當我執行此,我得到的服務名稱如預期。
if ($Service.Status -eq "Stopped") {
Write-Host "Service is stopped"
$dataRow = "<tr><td width='10%'>199.199.50.512</td><td width='10%' >$Service</td><td width='10%' align='center'>Stopped</td></tr>"
Add-Content $ServiceReport $dataRow;
}
這裏那裏$Service
寫,我expecing我的服務名稱,但我在HTML報告中得到System.ServiceProcess.ServiceController
。
HTML報告: