IP, DNS and gateway configuration of active adapters
Win32_NetworkAdapterConfiguration describes the IP configuration of each adapter. The IPEnabled = TRUE filter drops the adapters without an active IP stack.
Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'IPEnabled = TRUE' |
Select-Object -Property @(
'Description'
'MACAddress'
'DHCPEnabled'
'DHCPServer'
@{ Name = 'IPAddress'; Expression = { $_.IPAddress -join ', ' } }
@{ Name = 'SubnetMask'; Expression = { $_.IPSubnet -join ', ' } }
@{ Name = 'Gateway'; Expression = { $_.DefaultIPGateway -join ', ' } }
@{ Name = 'DnsServer'; Expression = { $_.DNSServerSearchOrder -join ', ' } }
'DNSDomain'
)
IPAddress, IPSubnet, DefaultIPGateway and DNSServerSearchOrder are arrays (IPv4 and IPv6 mixed): -join puts them on one line. In IPSubnet, IPv4 has a mask (255.255.255.0) and IPv6 has a prefix length.
Variant: remote
The methods EnableStatic, SetGateways and SetDNSServerSearchOrder change the configuration: they are not used here.
$cimSession = New-CimSession -ComputerName 'SERVER01', 'SERVER02'
try {
$cimParameters = @{
CimSession = $cimSession
ClassName = 'Win32_NetworkAdapterConfiguration'
Filter = 'IPEnabled = TRUE'
}
Get-CimInstance @cimParameters |
Select-Object -Property PSComputerName, Description, IPAddress, DefaultIPGateway
} finally {
Remove-CimSession -CimSession $cimSession
}