用于测试Ping和WinRM端口的Powershell脚本?
如何使用PowerShell为我的大部分服务器检查Ping测试和TCP WinRM用于测试Ping和WinRM端口的Powershell脚本?,powershell,Powershell,如何使用PowerShell为我的大部分服务器检查Ping测试和TCP WinRM Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*"} -Properties OperatingSystem | Select-Object Name,OperatingSystem | ForEach-Object { $comp = $_ Test-NetConnec
Get-ADComputer -Filter {Enabled -eq $True -and OperatingSystem -like "*Server*"} -Properties OperatingSystem | Select-Object Name,OperatingSystem |
ForEach-Object {
$comp = $_
Test-NetConnection -ComputerName $comp.Name -CommonTCPPort WINRM |
Select-Object ComputerName,PingSucceeded,TcpTestSucceeded,@{n="OS";e={$comp.OperatingSystem}} |
Tee-Object -Variable result
If ( $result.TcpTestSucceeded )
{
Write-Host "$($comp.Name) Connect WinRM - success"
}
ElseIf ( -not $result.TcpTestSucceeded )
{
Write-Host "$($comp.Name) Connect WinRM - failed"
}
ElseIf ( -not $result.PingSucceeded )
{
Write-Host "$($comp.Name) is offline."
}
} | OGV
因为上面代码的问题是PingSuccessed列将始终设置为FALSE,即使我手动ping服务器返回reply或True