Syntax: Check-service computername
I use this function to check all services on a machines for start state and if they are running. Get-service does not include startmode so I need to get -wmiobject of each service first. If the state is set to auto and the service is not running the script will prompt to start the service. I put this in my $profile so if is already ready to go. Enjoy
1 2 3 4 5 6 7 8 9 10 11 12 13 |
Function Check-service { Param ($servername) $svc=$null $svc = Get-WmiObject -ComputerName $servername -Class Win32_Service -Filter "Startmode='Auto'" foreach($item in $svc){if ($item.state -eq "Stopped"){get-service -Name $item.name -ComputerName $servername}} write-host "......................." foreach($item in $svc){if ($item.state -eq "Stopped") {$resonse = $null $response = read-host "Do you want to start" $item.name " Y/N" If ($response -eq "y" -or$response -eq "Y") {Set-Service -computername $servername -name $item.name -StatusRunning} } } } |