Monday, June 15, 2015

Get Network Info from list of servers - DNS, IP, WINS

Hi Readers,

Just sharing a script created by my colleague to get assigned IP, DNS, Wins information from List of servers.

I have finished its review & now uploading to to the gallery.

Extract the zip file from below link, populate the servers.txt file. (make sure you are running from the account that has admin access to the servers)

https://gallery.technet.microsoft.com/scriptcenter/Get-Network-Info-from-list-15fa2dd3



Run the batch file & you will get the result in the same folder as Networkinfo.csv.





######################################################################### 
#            Author: Diwakar Sharma 
#            Reviewer: Vikas Sukhija 
#            Date: 06/10/2015 
#            Reviewed: 06/15/2015 
#            Desc: Collect Network info from Nics 
######################################################################### 
 
$Collection = @() 
 
$ComputerNAme = get-content .\servers.txt 
 
foreach ($Computer in $ComputerName) { 
 
  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) { 
   $Networks = $null 
   $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer -ea silentlycontinue | ? {$_.IPEnabled} 
 
if($Networks){ 
     
foreach ($Network in $Networks) { 
 
    $IPAddress = $null 
    $SubnetMask = $null 
    $DefaultGateway$null 
    $DNSServers = $null 
    $WINSPrimaryserver = $null 
    $WINSSecondaryserver = $null 
    $IsDHCPEnabled = $null 
 
    $IPAddress  = $Network.IpAddress[0] 
 
    $SubnetMask  = $Network.IPSubnet[0] 
 
    $DefaultGateway = $Network.DefaultIPGateway -join ',' 
 
 
    $DNSServers  = $Network.DNSServerSearchOrder -join ',' 
 
    $WINSPrimaryserver = $Networks.WINSPrimaryServer 
    $WINSSecondaryserver = $Networks.WINSSecondaryserver 
 
 
    $IsDHCPEnabled = $false 
 
    If($network.DHCPEnabled) { 
     $IsDHCPEnabled = $true 
    } 
 
    $OutputObj  = New-Object -Type PSObject 
    $OutputObj | Add-Member -MemberType NoteProperty -Name ComputerName -Value $Computer.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 DNSServers -Value $DNSServers 
    $OutputObj | Add-Member -MemberType NoteProperty -Name WINSPrimaryserver -Value $WINSPrimaryserver 
    $OutputObj | Add-Member -MemberType NoteProperty -Name WINSSecondaryserver -Value $WINSSecondaryserver 
 
    $OutputObj 
 
$Collection +$OutputObj 
 
          } 
      } 
 } 
 

 
$Collection | export-csv .\Networkinfo.csv –notypeinformation 
 
###############################################################################




Regards

Sukhija Vikas

http://msexchange.me

 

No comments:

Post a Comment