$computer = [ordered]@{'www.google.com' = 443; 'www.baidu.com' = 80}
Foreach ($com in $computer.Keys) {
Test-NetConnection -ComputerName $com -Port $($computer[$com])
}
各位好,我自己寫了一段PowerShell,因想使用PRTG進行監控,
故需要抓取Script 結果中,TcpTestSucceeded的這個值,我可以用什麼指令取得這個值呢?
(Test-NetConnection -ComputerName $com -Port $($computer[$com])).TcpTestSucceeded
$computer = [ordered]@{'www.google.com' = 443; 'www.baidu.com' = 80}
$result = @()
Foreach ($com in $computer.Keys) {
$result += Test-NetConnection -ComputerName $com -Port $($computer[$com]
}
$result[0].ComputerNmae
$result[0].TcpTestSucceeded
$result[1].ComputerNmae
$result[1].TcpTestSucceeded
$computer = [ordered]@{'www.google.com' = 443; 'www.baidu.com' = 80}
$result = @{}
Foreach ($com in $computer.Keys) {
$result.add($com,(Test-NetConnection -ComputerName $com -Port $($computer[$com])))
}
$result['www.google.com'].ComputerName
$result['www.google.com'].TcpTestSucceeded
$result['www.baidu.com'].ComputerName
$result['www.baidu.com'].TcpTestSucceeded