Get WinRm service status on Multiple servers

I run:

$server = Get-Content -path C:\ServerList.txt
$server | foreach { (Get-Service -Name WinRM* -computername $) | Where {$.Status -eq “Stopped”}
Select-Object Status, Name, DisplayName |
ConvertTo-CSV | Out-File “C:\winrmstatus.csv”}

Not getting what I want in csv, it is blank.

Are you sure the service is stopped? If you query a specific service and it’s started, your where command isn’t going to return anything.

There is only one WinRM service, so the WinRM* is not really a thing to use.

Note, if it won’t print to the screen, it won’t go to a file.
Try it this way instead.

     (Get-ADComputer -Filter *).Name | %{
     Get-Service -Name WinRM -ComputerName $_ `
     | Select MachineName,Status,Name,DisplayName `
     | Where Status -eq 'Running'
     } | Format-Table -AutoSize


    MachineName   Status Name  DisplayName                              
    -----------   ------ ----  -----------                              
    DC01     Running WinRM Windows Remote Management (WS-Management)
    EX01     Running WinRM Windows Remote Management (WS-Management)
    SQL01    Running WinRM Windows Remote Management (WS-Management)
    ...

That should be

(Get-ADComputer -Filter *).Name | 
 foreach {
     Get-Service -Name WinRM -ComputerName $_ | 
     Select MachineName,Status,Name,DisplayName | 
     Where Status -eq 'Running'
     } | Format-Table -AutoSize

Never use % as an alias in scripts
The pipe symbol is treated as a line continuation character so using ` is redundant AND very hard to see in many editors

Running your cmd Richard returns:
Get-Service : Cannot find any service with service name ‘WinRM’.
At line:3 char:6

  •  Get-Service -Name WinRM -ComputerName $_ |
    
  •  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    
    • CategoryInfo : ObjectNotFound: (WinRM:String) [Get-Service], ServiceCommandException
    • FullyQualifiedErrorId : NoServiceFoundForGivenName,Microsoft.PowerShell.Commands.GetServiceCommand

Essentially trying to query a list of servers and need a csv returned with status of service whether it is stopped or started would be nice.

The code to get that is in your original post, the problem is you are asking for only where the service is stopped.

So taking your original code, and fixing it:

$server = Get-Content -path C:\ServerList.txt
$server | foreach { get-service -computername $_ -servicename winrm | select machinename, status, name, displayname } | export-csv C:\report.csv

Jon,

Thank you! that worked!