PowerShell code snippet to get network interface card/s (NICs) IP Address configuration.
If the server or workstation has multiple NIC's configured, code snippet below will get all the NIC's info.
The script can be modified to get the IP Address of remote computers or servers. An example code below shows on how to get IP Address of remote machines.
====================
#Display all NIC's with Static IP Address settings
$xdata = Get-WmiObject -Class Win32_NetworkAdapterConfiguration
Foreach ($xElement in $xdata) {
if ($xElement.IPAddress -ne $null -and $xElement.DHCPEnabled -eq $False) {
write-output $xElement
}
}
=====================
#Display all NIC's with IP Address configuration (DHCP and Static settings)
$xdata = Get-WmiObject -Class Win32_NetworkAdapterConfiguration
Foreach ($xElement in $xdata) {
if ($xElement.IPAddress -ne $null) {
write-output $xElement
}
}
====================
Sample output:
To tweak the script to get IP Address of remote computers or servers, use a PowerShell function and a text file with the list of server names or computer names.
Here's the script to do it:
==========================
function get_ip ($pcName)
{
$xdata = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -computername $pcName
Foreach ($xElement in $xdata) {
if ($xElement.IPAddress -ne $null) {
write-output $pcName $xElement
}
}
}
$computers = Get-content "D:\computers.txt"
ForEach ($Line In $computers)
{ get_ip $Line }
==========================
Cheers!! Hope it helps..
Comments
Post a Comment