Get Nic adapter information via wmi

Hi to all

here is my project.  Query a server and retrieve network information

- IP Address

- Submask

- Gateway

- DNS

-DNS Domain Suffixes

then put them into a html format list

hre is my code

$date  = get-date -Format g
$htmlfilepath = "C:\Scripts\report.html"
$csspath = "C:\Scripts\style.css"


$servername = 'servername.com' #Read-host "Enter Server DNS Name l"
$cred = Get-Credential -Message "Enter your Domain Credentials" -UserName "your credentials"

#Network Information
$nwINFO = Get-WmiObject -Class win32_NetworkAdapterConfiguration -ComputerName $servername -Credential $cred |
                        Where-Object { $_.IPAddress -ne $null } |

                         fl DNSDomainSuffixSearchOrder,DNSServerSearchOrder,IPAddress,DefaultIPGateway,IPSubnet, MACAddress




$nwinfo2 = @{ 'IPAddress' = $nwINFO.IPAddress};

           @{ 'Gateway' = $nwINFO.DefaultIPGateway};
           @{ 'MacAddress' = $nwINFO.MACAddress};

           @{ 'IPAddress' = $nwINFO.IPAddress};

$obj =  New-Object -TypeName psobject -Property $nwinfo2

$obj |ConvertTo-Html -as List |Out-File "c:\temp\test.html"

on the screen i get this

IPAddress                     : {10.222.62.145}
DefaultIPGateway        : {10.222.62.129}
IPSubnet                      : {255.255.255.192}
MACAddress                 : 00:50:56:81:52:00

but on the HTML I get

*: System.String[]

can anyone help me to get it right?

and explain what's going on

July 22nd, 2015 1:23pm

First you need to replace fl with select. You should never use any of the Format-* cmdlets if you plan on using the data. The reason you are getting an array (String[]) is because a NIC can have multiple IP addresses. In this case you only have one. If all of your network adapters have only one IP you can do this: $nwINFO.IPAddress[0]
Free Windows Admin Tool Kit Click here and download it now
July 22nd, 2015 2:12pm

Here is an HTML starter that may help you in your quest

https://gallery.technet.microsoft.com/scriptcenter/Sytem-Information-Using-0f7ff059

July 22nd, 2015 3:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics