Start multiple services on a list of computers

I'm trying to write a PowerShell script to start multiple services for a computer list in a txt file.  I know there has to be a way, but I'm running in circles trying to figure it out.  My latest test is

Get-ContentD:\Scripts\test.txt|Foreach-Object{Get-Service-Name 'spooler'|Set-Service-StatusRunning}

Which starts the service on the server I'm running the script from.  Also, the services I want to run are not on the server.

I'd appreciate any help.

February 26th, 2015 1:01pm

Get-ContentD:\Scripts\test.txt |
    Foreach-Object{
        Get-Service-Name 'spooler' -Computer $_ |Start-Service
    }		
Free Windows Admin Tool Kit Click here and download it now
February 26th, 2015 1:04pm

Hello Geek127,

                        If your sample text.txt file contains a list of computernames (one per row), then you simply need to add the "-computername parameter to the Get-Service command follower by the PS default variable $_.

Get-Content D:\Scripts\test.txt | Foreach-Object{Get-Service -Name 'spooler'  -Computername $_ | Set-Service-StatusRunning }

for reference, you can check this great post from the scripting guy http://blogs.technet.com/b/heyscriptingguy/archive/2013/10/13/powertip-use-poweshell-to-start-service-on-remote-machine.aspx

hope it helps

February 26th, 2015 1:10pm

Thank you Mariano and jrv.  Much appreciated!

Free Windows Admin Tool Kit Click here and download it now
February 26th, 2015 1:58pm

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

Other recent topics Other recent topics