lara400
lara400

Reputation: 4736

Ping TimeToLive - just get back number

when I do this:

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

I get back:

@{TimeToLive=128}

How do I just get the number out and not the @ thing around it?

I need it as I call it later in the below...which is erroring I think becuase it is not just looking at the number only:

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

Error:

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

Upvotes: 0

Views: 68

Answers (1)

arco444
arco444

Reputation: 22831

Two options:

Either use the -ExpandProperty parameter in your Select-Object

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

Or access the property directly on the variable you assign the object to

> $result = Get-WmiObject win32_pingstatus -Filter "Address='localhost'" | Select-Object TimeToLive
> $result.TimeToLive
128

Upvotes: 2

Related Questions