$Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName "WorkstationID"-EA Stop | ? {$_.IPEnabled}
$OutputObj = New-Object -Type PSObject -ErrorAction Stop
foreach ($Network in $Networks)
{
$IPAddress = $Network.IpAddress[0]
$SubnetMask = $Network.IPSubnet[0]
$DefaultGateway = $Network.DefaultIPGateway[0]
$DNSServers1 = $Network.DNSServerSearchOrder[0]
$DNSServers2 = $Network.DNSServerSearchOrder[1]
$MACAddress = $Network.MACAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $wid.ToUpper()
$OutputObj | Add-Member -MemberType NoteProperty -Name IPAddress -Value $IPAddress
$OutputObj | Add-Member -MemberType NoteProperty -Name SubnetMask -Value $SubnetMask
$OutputObj | Add-Member -MemberType NoteProperty -Name Gateway -Value $DefaultGateway
#$OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled
$OutputObj | Add-Member -MemberType NoteProperty -Name PrimaryDNSServers -Value $DNSServers1
$OutputObj | Add-Member -MemberType NoteProperty -Name SecondaryDNSServers -Value $DNSServers2
#$OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
$OutputObj | Export-Csv -Path "path/info.csv" -Append -Encoding UTF8
}
No comments:
Post a Comment