Windows Server TechCenter > Windows Server Forums > Windows PowerShell > Query Service State and if not stopped, stop it
Ask a questionAsk a question
 

AnswerQuery Service State and if not stopped, stop it

  • Thursday, August 20, 2009 9:36 PMKanien Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I have 15 services across 3 servers that I have to stop in a specific order and start in a specific order.

    Here is what I have so far..

    $services = Import-Csv "aspect_services.csv"
    foreach($entry in $services) {
        $server = $entry.Server
        $service = $entry.service
        C:\Users\davidf\Downloads\SysinternalsSuite\psexec.exe \\$Server net stop $service
    }

    Instead I'd like to do something with the Get-Service command.  Can I run a Get-Service on a remote machine?  How?  I'd like to get the status of the service and if it isn't stopped then try to stop it.

Answers

All Replies

  • Thursday, August 20, 2009 11:16 PMMarco ShawMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Proposed Answer
    Limited to PowerShell v1 or can you use v2?  Just asking, chances are it is v1, and you won't be able to use Get-Service to do stuff remotely.  Do you know if you can use WMI to connect to remote machines.
  • Friday, August 21, 2009 6:07 AMMervyn ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hi,

     

    The following article may help:

     

    How Can I Use Windows PowerShell to Start a Service on a Remote Computer?

    http://www.microsoft.com/technet/scriptcenter/resources/qanda/jun06/hey0621.mspx

     

    If you’re using V2, try to run "get-help About_Remoting" to get detailed information about remoting.

     

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights.
  • Thursday, August 27, 2009 6:13 AMMervyn ZhangMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    Hi,

    Do you need any other assistance? If there is anything we can do for you, please let us know.

    Thanks.


    This posting is provided "AS IS" with no warranties, and confers no rights.