PowerShell

Get Network Information of local and remote Computers using PowerShell.

Hi,

Last Sunday one of my friend come to visit me at my home, he is a SQL Administrator and we were talking about Powershell, and he told me that he is facing a problem, he said that in their environment they have approx. 500 Servers and they want to know the network configuration of all of them and specially they needed the SUBNET mask information, because their SUBNETMASK are based on geographic locations.

For him i wrote a simple script which can query multiple server using WMI.

Download the script from this linkhttp://gallery.technet.microsoft.com/scriptcenter/Get-Network-Information-of-6d07766f

18-09-2012 12-52-23

You need to add computer names separated by commas in the front of the script.

Make sure that you run this script as ADMINISTRATOR if you want to run this script for remote computers.

Download the script from this link : http://gallery.technet.microsoft.com/scriptcenter/Get-Network-Information-of-6d07766f

Thanks

Aman Dhally

join aman on facebook Join aman on Linkedin follow aman on Twitter

11 thoughts on “Get Network Information of local and remote Computers using PowerShell.

  1. Hi Aman!
    Alex from FB-ScriptingGuys-Group here…

    I ran your script on my computer, but I received no results..
    Doing some reseach, I found out, that the $nwINFO variable formed an array, because I have more than one active network adapter.
    So I was curious how to solve that…

    Here is my approach, which works for me and I want to share (as you always share your scripts for the community 🙂 )

    ————————
    foreach ( $Computer in $arrComputer ) {

    $nwINFO = Get-WmiObject -ComputerName $Computer Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } #| Select-Object DNSHostName,Description,IPAddress,IpSubnet,DefaultIPGateway,MACAddress,DNSServerSearchOrder | format-Table * -AutoSize
    #| Select-Object DNSHostName,Description,IPAddress,IpSubnet,DefaultIPGateway,MACAddress,DNSServerSearchOrder
    For ($i = 0; $i -lt $nwINFO.count; $i++) {
    $nwServerName = $nwINFO[$i].DNSHostName
    $nwDescrip = $nwINFO[$i].Description
    $nwIPADDR = $nwINFO[$i].IPAddress
    $nwSUBNET = $nwINFO[$i].IpSubnet
    $nwGateWay = $nwINFO[$i].DefaultIPGateway
    $nwMacADD = $nwINFO[$i].MACAddress
    $nwDNS = $nwINFO[$i].DNSServerSearchOrder
    # Server/CompName |NetworkCard | IPAdress | SubnetMask| Gateway | MAC Address| DNS |
    Write-Host “$nwServerName | $nwDescrip | $nwIPADDR | $nwSUBNET | $nwGateWay | $nwMacADD | $nwDNS ” | ft *
    }

    }
    ————————

    Cheers,
    Alex

    1. HI Alex,
      Nice find and actually i never think that someone may have two or more IP Enabled Connections..

      Thanks for correction and as i say from sharing everyone gets benefited and everyone learn new things.

      Thanks for share 🙂 and i do know you ;o)

      Thanks
      Aman

    2. Hi,

      There is another alternative to this, by inserting another ‘foreach’ loop.

      param (
      [array]$arrComputer=”$env:computername”
      )

      “`n”

      Write-Host “Name| NetworkCard | IP | SUBNET | GateWay | MacADD | DNS ” -ForegroundColor Green

      foreach ( $Computer in $arrComputer ) {

      $nwINFO = Get-WmiObject -ComputerName $Computer Win32_NetworkAdapterConfiguration | Where-Object { $_.IPAddress -ne $null } #| Select-Object DNSHostName,Description,IPAddress,IpSubnet,DefaultIPGateway,MACAddress,DNSServerSearchOrder | format-Table * -AutoSize
      foreach ($info in $nwinfo) {#| Select-Object DNSHostName,Description,IPAddress,IpSubnet,DefaultIPGateway,MACAddress,DNSServerSearchOrder
      $nwServerName = $INFO.DNSHostName
      $nwDescrip = $INFO.Description
      $nwIPADDR = $INFO.IPAddress
      $nwSUBNET = $INFO.IpSubnet
      $nwGateWay = $INFO.DefaultIPGateway
      $nwMacADD = $INFO.MACAddress
      $nwDNS = $INFO.DNSServerSearchOrder
      # Server/CompName |NetworkCard | IPAdress | SubnetMask| Gateway | MAC Address| DNS |
      Write-Host “$nwServerName | $nwDescrip | $nwIPADDR | $nwSUBNET | $nwGateWay | $nwMacADD | $nwDNS ” | ft * }

      }

  2. Hi, great script. I was wondering what command should I use to export results into csv. I tried to put export-csv filename.csv at the end, and it doesn’t work. Colld you please assist. Thank you.

  3. HI Aman,
    when I run the script I got no values returns so do you have an idea what might be the reason for that?
    Thanks,
    Peter

Comments are closed.