none
Start multiple services on a list of computers RRS feed

  • Question

  • 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.

    Thursday, February 26, 2015 5:58 PM

Answers

  • 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


    Best Regards / Saludos, Marianok

    Disclaimer: This post, and all included code and information is provided "AS IS" with no warranties or guarantees and confers no rights. Try it at your own risk, I take no responsibilities.

    Aclaración: Esta publicación, y todo en código e información en la misma, es provista "AS IS" / "Como Está" sin garantía alguna y no le confiere ningún derecho. Pruebelo su propio riesgo. No asumo responsabilidad alguna.

    • Marked as answer by G127 Thursday, February 26, 2015 6:54 PM
    Thursday, February 26, 2015 6:06 PM

All replies

  • Get-ContentD:\Scripts\test.txt |
        Foreach-Object{
            Get-Service-Name 'spooler' -Computer $_ |Start-Service
        } 


    ¯\_(ツ)_/¯


    • Edited by jrv Thursday, February 26, 2015 6:01 PM
    Thursday, February 26, 2015 6:00 PM
  • 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


    Best Regards / Saludos, Marianok

    Disclaimer: This post, and all included code and information is provided "AS IS" with no warranties or guarantees and confers no rights. Try it at your own risk, I take no responsibilities.

    Aclaración: Esta publicación, y todo en código e información en la misma, es provista "AS IS" / "Como Está" sin garantía alguna y no le confiere ningún derecho. Pruebelo su propio riesgo. No asumo responsabilidad alguna.

    • Marked as answer by G127 Thursday, February 26, 2015 6:54 PM
    Thursday, February 26, 2015 6:06 PM
  • Thank you Mariano and jrv.  Much appreciated!

    Thursday, February 26, 2015 6:55 PM