Skip to content

Instantly share code, notes, and snippets.

@SweetAsNZ
Created July 13, 2022 22:52
Show Gist options
  • Save SweetAsNZ/05431ca6d464f3e1aadfe84e582fcd4d to your computer and use it in GitHub Desktop.
Save SweetAsNZ/05431ca6d464f3e1aadfe84e582fcd4d to your computer and use it in GitHub Desktop.
Check/Test WinRM On All Domain-Joined Servers
function Get-WinRMServerFailures
{
# Ping a Server and if it responds test WINRM
$Log = 'C:\SCRIPTS\WinRM\Servers_WinRMFailed.log'
Remove-Item $Log
$Servers = (Get-ADComputer -Filter * -Properties Name,OperatingSystem,Enabled | Where {($_.Enabled -eq $true) `
-and ($_.OperatingSystem -like "Windows Server*")} | Sort Name).Name
foreach ($Server in $Servers)
{
# $Server = 'SERVER1' # Testing
# Ping the Server and if it responds
if(Test-Connection -ComputerName $Server -Count 1 -Quiet){
# Test WinRM
$TestWinRM = Test-NetConnection -ComputerName $Server -CommonTCPPort WINRM #-ErrorAction Stop
if($TestWinRM.TCPTestSucceeded -eq $false){
Add-Content -Path $Log -Value $Server
}
}#END IF BIG
}#END FOREACH
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment