Чтение файла для проверки состояния служб
$strFile = "c:\fso\StoppedServices.txt" Get-Content $strFile | foreach-object { $strService = $_.trimend() $strQuery = "Select * from win32_service where name ='$strService'" get-wmiobject -query $strQuery | foreach-object ` { if ($_.state -eq "stopped" ) { Write-Host $_.name "is still stopped" } ELSE { Write-Host -foregroundcolor RED $_.name ` " is no longer stopped. It is $($_.state)" } } }
Проверка, что работают нужне службы -
$strFile = "c:\fso\runningservices.txt" Get-Content $strFile | foreach-object { $strService = $_.trimend() $strQuery = "Select * from win32_service where name ='$strService'" get-wmiobject -query $strQuery | foreach-object ` { if ($_.state -eq "running" ) { Write-Host $_.name "is still running" } ELSE { Write-Host -foregroundcolor RED $_.name ` " is no longer running. It is $($_.state)" } } }
Голосов пока нет
Оставить комментарий