How to check service status are running or stopped on remote servers

D Vijayakumar VLR 126 Reputation points
2021-03-27T12:14:18.807+00:00

Hi All,

How to check service status are running or stopped on multiple remote servers and i want output file like ServerName, ServiceName, Status, StartupType

Windows for business | Windows Server | User experience | PowerShell
{count} votes

2 answers

Sort by: Most helpful
  1. Andreas Baumgarten 123.4K Reputation points MVP Volunteer Moderator
    2021-03-27T12:54:26.733+00:00

    Hi @D Vijayakumar VLR ,

    Maybe this is helpful:

    $servernames = "server1","server2"  
    $file = "C:\Junk\ResultServices.txt"  
    $result = "ServerName;Service;Status;StartType`r`n"  
    foreach ($Server in $Servernames){  
        $services = Get-service -ComputerName $server  | select Name, Status, StartType | Foreach-Object {  
            $result += $server + ";"+  $_.name + ";" + $_.Status + ";" + $_.StartType + "`r`n"  
            }  
        }  
    $result > $file  
    

    ----------

    (If the reply was helpful please don't forget to upvote and/or accept as answer, thank you)

    Regards
    Andreas Baumgarten


  2. Rich Matheisen 47,901 Reputation points
    2021-03-27T14:34:28.983+00:00

    You can try either of these two examples:

    # get server names from array
    $servernames = "server01","server02","server03"
    Get-service -ComputerName $servernames  | 
        Select-Object MachineName, Name, DisplayName, Status, StartType
    
    # get server names from a file
    $serverfile = "c:\junk\list-of-names.txt"
    Get-service -ComputerName (Get-Content $serverfile)  | 
        Select-Object MachineName, Name, DisplayName, Status, StartType
    

    If you like you can sort the output, export it to a CSV file, convert it to JSON, convert it to HTML, etc. You can also select what service status you're interested in (e.g. Stopped, Running, etc.) before sending it to a file.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.