I wrote a script to tell me if the SEP Master Service is running for all computer listed in a file, start the service if its stopped, and let me know if it doesn't exist. It seems to work with starting the service, but i'm having issues seeing the output for the status on each computer. If the service is running on each computer in the list, it'll show me the output fine. If one of the computer doesn't have the service running, it is started, but i don't see the write-output message from the first if statement, for the computers that already had the service running. What i'll like to see is the output showing the running status for all machines with the service running, when the services is started on machines where it was stopped, and would like to see the message telling me what machines the service is not on.
$computers = Get-Content -Path "C:\temp2\generic_service2.bat"
$serivce = Get-Service -name SepMasterService -computername $computer
foreach ($computer in $computers) {
$ServiceStatus = $serivce.Status
$ServiceDisplayName = $serivce.DisplayName
if ($ServiceStatus -eq 'Running') {
Write-Output "Service OK - Status of $ServiceDisplayName is $ServiceStatus on $computer"
}
elseif ($ServiceStatus -eq 'stopped') {
Start-Service -Name SepMasterService -PassThru
}
else {
Write-Output "Service doesn't exist"
}
}