Posted in
Windows Powershell,
Windows Server |
No Comment | 2,486 views | 24/03/2014 11:02
You can query network adapter information via WMI. Just add your all hosts into Servers.txt and use following script:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
| $Servers = Get-Content Servers.txt
foreach ($Server in $Servers)
{
$ErrorActionPreference = "silentlycontinue"
$Ping = New-Object System.Net.Networkinformation.ping
$Status = $Null
$Status = ($Ping.Send("$Server", 1)).Status
if ($Status -eq "Success")
{
ForEach ($Adapter in (Get-WmiObject Win32_NetworkAdapter -ComputerName $Server))
{
$Config = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "Index = '$($Adapter.Index)'" -ComputerName $Server
if ($Config.IPAddress)
{
$Output = $Server + ";" + $Adapter.Name + ";" + $Config.IPAddress[0] + ";" + $Config.MacAddress
Write-Host $Output
}
}
}
} |
$Servers = Get-Content Servers.txt
foreach ($Server in $Servers)
{
$ErrorActionPreference = "silentlycontinue"
$Ping = New-Object System.Net.Networkinformation.ping
$Status = $Null
$Status = ($Ping.Send("$Server", 1)).Status
if ($Status -eq "Success")
{
ForEach ($Adapter in (Get-WmiObject Win32_NetworkAdapter -ComputerName $Server))
{
$Config = Get-WmiObject Win32_NetworkAdapterConfiguration -Filter "Index = '$($Adapter.Index)'" -ComputerName $Server
if ($Config.IPAddress)
{
$Output = $Server + ";" + $Adapter.Name + ";" + $Config.IPAddress[0] + ";" + $Config.MacAddress
Write-Host $Output
}
}
}
}
After that you will see all network adapters and ip configurations.