Getting IPv4 Addresses

You should use WMI to list all IPv4 addresses assigned to a computer:

Get-WMIObject win32_NetworkAdapterConfiguration |
Where-Object { $_.IPEnabled -eq $true } |
Foreach-Object { $_.IPAddress } |
Foreach-Object { [IPAddress]$_ } |
Where-Object { $_.AddressFamily -eq 'Internetwork' } |
Foreach-Object { $_.IPAddressToString }

You can also query remote systems this way since Get-WMObject supports -ComputerName. The trick to focusing on IPv4 only is to convert the IP address to the type IPAddress and then check that its AddressFamily is "InterNetwork."

Twitter This Tip! ReTweet this Tip!


Posted May 17 2010, 08:00 AM by ps1

Comments

Twitter Trackbacks for Getting IPv4 Addresses - Power Tips - PowerShell.com [powershell.com] on Topsy.com wrote Twitter Trackbacks for Getting IPv4 Addresses - Power Tips - PowerShell.com [powershell.com] on Topsy.com
on 05-17-2010 9:30 AM

Pingback from  Twitter Trackbacks for                 Getting IPv4 Addresses - Power Tips - PowerShell.com         [powershell.com]        on Topsy.com

Concentrated Tech NSoftware Dell Compellent Sponsored by Idera and Concentrated Tech and NSoftware and Dell Compellent
Copyright 2011 PowerShell.com. All rights reserved.