Search and start all automatic services, those are in stopped on multiple computers.

Hi All,

I am trying to achieve following two.

  1. Search all automated services on multiple remote system, those are in stooped.
  2. Start all of all of them.

I am able to extract the information for first one using following.

Get-Wmiobject -computername (get-Content c:\servers.txt) win32_service | Where-Object {($_.StartMode -eq "Auto") -and ($_.State -eq "Stopped")}|select SystemName,Name,StartMode,State,Status|ft

But I am not able to start them by using ForEach-Object {Start-Service $_.Name} at end, if I do so, it's trying to start those services on the local system.

I am able to do it on a single or multiple system by using 

Get-WmiObject -ComputerName SERVER1,SERVER2 Win32_Service | Where-Object {($_.StartMode -eq "Auto") -and ($_.State -eq "Stopped")}| ForEach-Object {Start-Service $_.Name}

Help is required for this.

PS: I am very new to PS. :(

June 26th, 2013 1:39pm

start-service is trying to start service on your local computer not remote servers, you are going to either need to start your results in a variable from search then do a foreach loop and use wmi to start it or something like this

Get-WmiObject -ComputerName "pcs" Win32_Service | Where-Object {($_.StartMode -eq "Auto") -and 
($_.State -eq "Stopped")}| ForEach-Object {($_).invokemethod("startservice",$null)}

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2013 3:36pm

You need to do it this way:

Get-WmiObject -ComputerName (cat servers.txt) -Class Win32_Service -FIlter "StartMode = 'Auto' and State = 'Stopped'" | 
     	ForEach-Object{
		$_.StartService()
	}

You will also find that most of the services will just stop again because they are designed that way.  They start and schedule a restart then shutdown.  The system restarts the service, it does some work then reschedules itself and quits again.

You should identify services that must be running and set a GPO to keep them running or to notify you when they fail via email.

June 26th, 2013 3:45pm

another way to do it is using following one-liner:

Get-Content c:\servers.txt | foreach { Get-WmiObject Win32_Service -ComputerName $_ | where {$_.startmode -eq "Auto" -and $_.state -eq "Stopped"} | foreach { $_.StartService() } }

make sure c:\servers.txt exists, or replace it with your actual file path. 


Free Windows Admin Tool Kit Click here and download it now
June 26th, 2013 4:35pm

another way to do it is using following one-liner:

Get-Content c:\servers.txt | foreach { Get-WmiObject Win32_Service -ComputerName $_ | where {$_.startmode -eq "Auto" -and $_.state -eq "Stopped"} | foreach { $_.StartService() } }

make sure c:\servers.txt exists, or replace it with your actual file path. 


June 26th, 2013 4:57pm

Sorry - my original post \of the code had -filter in it twice.  I edited the original.

Free Windows Admin Tool Kit Click here and download it now
June 26th, 2013 4:58pm

Thank you all for helping me out.

July 3rd, 2013 11:35pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics