Skip to content
Menu
Tech Automation Blog
  • About Author
  • Contact
Tech Automation Blog

WinRM status check using Powershell

Posted on September 1, 2019February 27, 2022

Here is another small script snippet I used in one of my project to quickly check status of WinRM setup on a list of servers I was managing. This was part of a bigger project work, and this data was important for my project on whether WinRM is setup as per requirements or not.

You need to provide a file path to a list of system names on which this script should be executed as parameter. Once executed, it will generate a csv file with WinRM status if the systems provided can be reachable from the system from which you run this script. Share your comments if it helps or if you face any issue.

Param(
	[Parameter(Mandatory=$true)]
	[String]$serverList
)
#Provide a text file path containing a list of server FQDN or IP Addresses which will be checked. 
if(!(Test-Path $serverList)){
	Write-Host "ERROR: Path not found.Check the path and try again!" -ForegroundColor Red
}
else{
	$currentDir = $(Get-Location).Path
	$oFile = "$($currentDir)\Server_WinRM_State.csv"

	if(Test-Path $oFile){
		Remove-Item $oFile -Force
	}
	if(Test-Path $oFile){Remove-Item $oFile -Force}

	"ServerName,WinRM Configured?,WinRM HTTP Port,WinRM HTTPS Port" | Out-File $oFile -Append -Encoding ASCII
	ForEach($srv in Get-Content $serverList){
		$winrmConfig = $winrmHTTP = $winrmHTTPS = ""
		# Checks if the System is responding to Ping and can be connected.
		Try{
			if(Test-Connection $srv -Count 2){
				# To Check WINRM configured or not:
				$winrmConfig = [system.convert]::ToBoolean(((winrm get winrm/config/winrs -r:$srv | Where-Object{$_ -imatch "AllowRemoteShellAccess"}).split("="))[1].trim())
		
				# To Check the Default HTTP listener port on a remote machine:
				$winrmHTTP = [System.Convert]:: ToInt32(((winrm get winrm/config/Service/DefaultPorts -r:$srv | Where-Object{$_ -imatch "HTTP = " }).split("="))[1].trim())
		
				# To Check the Default HTTPS listener port on a remote machine:
				$winrmHTTPS = [System.Convert]:: ToInt32(((winrm get winrm/config/Service/DefaultPorts -r:$srv | Where-Object{$_ -imatch "HTTPS = " }).split("="))[1].trim())
			}
			"$srv,$winrmConfig,$winrmHTTP,$winrmHTTPS" | Out-File $oFile -Append -Encoding ASCII	
		}
		catch{
			Write-Error -Message $_.Exception
		}
	}	
}

Download above script and save it to your local drive and create a text file with list of server FQDN or IP address to get the status of WinRM. After that, run the script as shown below.

Execute powershell script

Verify the csv file generated as output of the execution.

Share this:

  • Click to share on X (Opens in new window) X
  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on LinkedIn (Opens in new window) LinkedIn
July 2025
M T W T F S S
 123456
78910111213
14151617181920
21222324252627
28293031  
« May    

Recent Posts

  • Monitor and alert Azure Service Health issues May 5, 2020
  • AWS IAM User access review May 3, 2020
  • Integrate Azure Security Center with Event Hub April 28, 2020
  • Add Tags to Azure Subscription April 24, 2020
  • Automate Azure billing report in Excel March 6, 2020

Categories

©2025 Tech Automation Blog | Powered by SuperbThemes