Powershell脚本提供以下结果表。我们需要确定VM是否可以访问,因此我想检查“时间”列是否为空。
问题:
如何检查“时间(毫秒)”是否有价值?一般情况下如何查询任何列或行?
$result = Test-ConnectionAsync "MyVm"
C:\$result
Source Destination IPV4Address IPV6Address Bytes Time(ms)
------ ----------- ----------- ----------- ----- --------
SourceVM MyVM 10.20.20.10 32 207
SourceVM MyVM 10.20.20.10 32 207
SourceVM MyVM 10.20.20.10 32 207
SourceVM MyVM 10.20.20.10 32 207
谢谢!
答案 0 :(得分:1)
您可以使用Where-Object
功能来检查给定行中任何列的值。如果要找出应该使用的列名,请使用Get-Member
获取该对象的所有属性或方法。
# Get all the properties of $result[0]
$result[0] | Get-Member
# Among other things, you will ResponseTime as one of the properties you can use.
# Check if Time(ms) has any value. Following will give you only those rows that match the condition
#Original where statement
#$result | Where-Object { $_.ResponseTime -ne $null }
#Updated where statement
$result | Where-Object { $null -ne $_.ResponseTime }