Ping TimeToLive - 只需返回号码

时间:2014-12-16 10:43:04

标签: powershell

当我这样做时:

$pinging = Get-WmiObject win32_pingstatus -Filter "Address='localhost'" | Select-Object TimeToLive

我回来了:

@{TimeToLive=128}

我如何才能获得号码而不是@周围的东西?

我需要它,因为我稍后会在下面调用它...这是错误的我认为这不仅仅是看数字:

Switch($pinging)
{
    {$_ -le 128} 
        {return "This is a Windows Server"; break}
}

错误:

Cannot compare "@{TimeToLive=128}" to "128" because the objects are not the same type or the object "@{TimeToLive=128}" does not implement "IComparable"

1 个答案:

答案 0 :(得分:2)

两个选项:

使用-ExpandProperty

中的Select-Object参数
> $result = Get-WmiObject win32_pingstatus -Filter "Address='localhost'" | Select-Object -expandproperty TimeToLive
> $result
128

或直接在您将对象分配给

的变量上访问该属性
> $result = Get-WmiObject win32_pingstatus -Filter "Address='localhost'" | Select-Object TimeToLive
> $result.TimeToLive
128