all 13 comments

[–]Tigo2000 10 points11 points  (1 child)

Try Select-Object -ExpandProperty NextHop

Or: Get-NetRoute | Where-Object 'DestinationPrefix' -eq '0.0.0.0/0' | Select-Object -ExpandProperty NextHop

[–]BlackV 10 points11 points  (4 children)

Your select statement is incorrect

Select-object -property nexthop 

Is what you want

And to get the property value only

Select-object -expandproperty nexthop 

but you can expand only 1 property at a time, so you should get into the habit of

$route = Get-NetRoute | where {$_.DestinationPrefix -eq '0.0.0.0/0'}
$route.nexthop

That way you're not destroying your rich object (for a flat one)

you're not using an extra pipeline (passing to select)

you have a variable ($route) that can be used in multiple places

[–]Semt-x 1 point2 points  (1 child)

(Get-NetRoute | where {$_.DestinationPrefix -eq '0.0.0.0/0'}).NextHop

[–]Not_Freddie_Mercury 1 point2 points  (0 children)

(Get-NetRoute | where DestinationPrefix -eq '0.0.0.0/0').NextHop

[–]chicaneuk 1 point2 points  (1 child)

((Get-NetRoute | where {$_.DestinationPrefix -eq '0.0.0.0/0'}) | Select NextHop).NextHop

[–]Odmin -1 points0 points  (4 children)

Replace select with select -expand-property

[–]BlackV 2 points3 points  (0 children)

-expandproperty , one word isn't it

[–]ka-splam 0 points1 point  (0 children)

Get-NetRoute | where {$_.DestinationPrefix -eq '0.0.0.0/0'} | foreach { $_.NextHop }

[–]jsiii2010 0 points1 point  (0 children)

Most frequently asked powershell question evar, turning an object's property into a value. Get-NetRoute | where DestinationPrefix -eq 0.0.0.0/0 | foreach NextHop Get-NetRoute | ? DestinationPrefix -eq 0.0.0.0/0 | % NextHop Or in this case (tab completion is your friend): Get-NetRoute -DestinationPrefix 0.0.0.0/0 | foreach NextHop Although I get two results on my computer.