Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting specific network information in PowerShell

I'm not sure if this is a fault by me, or if my PowerShell isn't operating correctly.

get-netipconfiguration | where {$_.subnetmask} 

I'm not really able to find any examples online that work either. I even tried using a WMI command and it still won't work. I have the latest version of PowerShell and have done this before, but my previous method is not working. Currently I'm using this for IPaddress fetching which works wonderfully

$ipaddress = (Get-NetIPConfiguration).IPv4Address.IPAddres

That works great, but I can't seem to figure out how I could use it to display the DNS and Subnet mask as well. I know this is probably a noob question, but they've changed a bit of stuff and I'm trying to find a cut and dry way of doing it without too much code. Any help is appreciated!

like image 259
cloudnyn3 Avatar asked Sep 13 '25 11:09

cloudnyn3


2 Answers

You could retrieve this information using WMI:

Get-WmiObject Win32_NetworkAdapterConfiguration | 
   Where IPEnabled | 
   Select IPSubnet, DNSServerSearchOrder, IpAddress
like image 120
Martin Brandl Avatar answered Sep 16 '25 09:09

Martin Brandl


With PWSH 7.x, WMI won't be available. So that will of course be:

Get-CimInstance Win32_NetworkAdapterConfiguration |
  Where IPEnabled |
    Select IPSubnet, DNSServerSearchOrder, IpAddress
like image 26
Dennis Avatar answered Sep 16 '25 09:09

Dennis