How to get the default gateway from powershell?

后端 未结 5 2227

If a computer has multiple gateways, how can I determine which is the default gateway using the PowerShell?

5条回答
  •  清歌不尽
    2020-12-18 05:38

    Use the WMI queries to pull the data that you're looking for. Below is a fairly simple example to pull the default gateway for a device specified in the first line variable. This will query the device for network adapters and display the found information (for each adapter) to the console window - pulls adapter index, adapter description, and default gateway

    Shouldn't take much to expand this to process multiple devices, or process based on a list fed via an input file.

    $computer = $env:COMPUTERNAME
    
    Get-WmiObject win32_networkAdapterConfiguration -ComputerName $computer | 
    Select index,description,defaultipgateway |
    Format-Table -AutoSize
    

提交回复
热议问题