Powershell script value fetching

后端 未结 2 1991
别那么骄傲
别那么骄傲 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:47

    You should get property value using either of following scripts.

    Using (your script).PropertyName:

    (Get-WmiObject -Class Win32_IP4RouteTable |
        where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} | 
            Sort-Object metric1 | select nexthop | select-object -first 1).nexthop
    

    Or by using Using your script | select -ExpandProperty PropertyName:

    Get-WmiObject -Class Win32_IP4RouteTable |
        where { $_.destination -eq '0.0.0.0' -and $_.mask -eq '0.0.0.0'} | 
            Sort-Object metric1 | select nexthop | select-object -first |
                select -ExpandProperty nexthop
    

提交回复
热议问题