This article explains how to pull IP address, subnet mask, DNS servers and Mac address of remote computers using a Powershell script.
If you are working as a system admin for a large IT enterprise you may come across to pull the current IP configuration of multiple desktops computers and windows servers, when there is migration from one host to another host we do need to pull the IP configuration report.
Using the WMI Powershell command we are going to pull the IP configuration of remote computers.
We need to create a text file for remote computers list that we are going to query the port status, here I have created a text file named as allservers.txt and saved it in location C\temp\allservers.txt
$allservers
$Allservers = Get-Content "C:\temp\Allservers.txt"
foreach($Server in $Allservers)
{
$Ipconfig= $null
$Ipcofig= Get-WmiObject -Class "win32_networkadapterconfiguration" -ComputerName $server
Write-Host "The Server"$server "IP, Subnet mask, DNS Servers and Mac address"
$Ipcofig.ipaddress; $Ipcofig.macaddress ; $Ipcofig.IPSubnet ; $Ipcofig.DefaultIPGateway
}
The above simple script gets the remote computer IP address, Subnet Mask, Default Gateway Address and DNS names.
One can also query the variable $ipconfig | gm to get more properties and get other information as well, for example if you want to query DHCP is enabled or not then you can use a property called DHCPenabled, in the script you need mention $ipconfig.DHCPenabled this gives you the status whether DHCP is enabled or not. Likewise using the variable properties one call pull other useful information.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in your lower environment before you run in production.
I hope you find this article useful if you have any questions please let us know.
Leave a Reply Cancel reply