Powershell script value fetching

后端 未结 2 1993
别那么骄傲
别那么骄傲 2021-01-14 04:54

I wanted to fetch default gatway using powershell script and I am able to get it as below.

Get-WmiObject -Class Win32_IP4RouteTable |
    where { $_.destinat         


        
2条回答
  •  臣服心动
    2021-01-14 05:25

    You don't have to use Select-Object cmdlet multiple time.

    Get-WmiObject -Class Win32_IP4RouteTable -Filter "Destination = '0.0.0.0' AND Mask = '0.0.0.0'" |    
            Sort-Object metric1 | Select-Object -First 1 -ExpandProperty nexthop
    

    or

    (Get-WmiObject -Class Win32_IP4RouteTable -Filter "Destination = '0.0.0.0' AND Mask = '0.0.0.0'" |    
            Sort-Object metric1 | Select-Object -First 1).nexthop
    

提交回复
热议问题