When you want to pull the IP address of multiple windows remote computers one definitely needs a Powershell script, this article explains how a simple Powershell code gets the IP address of multiple computers.
IT administrators often work on IP address change the servers or VM’s migrated to different host (VMware or Citrix or Microsoft Hyper-V) they need to change the IP address and validate later, because they move the VM to different VLAN or Network.
Powershell Script get IP Address
We need to create a file for storing all the servers or multiple machines list, I named it as Allservers.txt for and saved it in my local machine c:\temp\Allservers.txt
$allservers = Get-Content -path "c:\temp\allservers.txt"
$index = @()
$ping = New-Object System.Net.NetworkInformation.Ping
#Looping each server
Foreach($Server in $allservers)
{
$ipaddress = $null
$Object = $null
$Value = $null
$ipaddress = ($ping.Send($Server).Address)
If($ipaddress)
{
$Value = $ipaddress.IPAddressToString
}
Else
{
$Value = "(not found)"
}
# Powershell custom object declaration
$Object = New-Object PSObject -Property ([ordered]@{
Server = $Server
IPAddress = $Value
})
# Add object to array
$index += $Object
#Display object
$Object
}
If($index)
{
#one can also export the report to specified location
$index | Export-Csv -Path C:\temp\computerips.csv -NoTypeInformation
}
Above script pulls the IP address of multiple remote computers and one can also save the report, this script by default it stores the CSV file in C:\temp\computerips.csv one change this path and use it as required.
The executor, who runs this script must have the proper rights to remote computers, if not one will run into permission or access denied issues, make sure you have admin rights on the remote computers.
Thank you for reading this article, if you have any questions please let us know.
Thank you for visiting my site, for any scripts in these articles you are testing please make sure you have tested this script in our lower environment before you run in production.
Leave a Reply Cancel reply