Reputation: 61
I want to retrieve IP address through powershell using GWMI but not using Win32_NetworkAdapterConfiguration classs. Please help.
Upvotes: 0
Views: 290
Reputation: 9173
There are multiple approaches . It depends on your PS version and requirement:
Dot Net method:
[net.dns]::GetHostAddresses("") | Select -ExpandProperty IPAddressToString
Native PS command using test-connection (equivalent to ping):
Test-Connection -ComputerName ::1 -Count 1 |Select-Object -Property IPv*Address
From Registry key:
Get-ChildItem -Path HKLM:\system\CurrentControlSet\services\Tcpip\Parameters\Interfaces| foreach{get-itemProperty $_.PSPath -N *IPAdd* -EA 0}|select *IP*
Using Ipconfig:
(ipconfig)-like'*IPv4*'|foreach{($_-split': ')[-1]}
If you are in PS Version 3 or above and Windows 8 / Server 2012 or above then directly you can use:
(Get-NetIPAddress).IPAddress
or (Get-NetIPConfiguration).IPv4Address
Hope it helps.
Upvotes: 2