Hi folks, this is a script to help you get network information from remote servers or clients.
You can use get-content to a list of server names or you can run to a single machine.
The information,includes,ComputerName,IPAddress,SubnetMask,Gateway,IsDHCPEnabled,DNSServers,WINSServers,MACAddress.

Here is the code



#How to run you can target one single machine , multiple or point to a .txt file where you have a set of servers.
# get-Content c:\temp\computers.txt | Get-IpDetails.ps1 | ft -auto
# .\get-Ipdetails.ps1 -computerName SERVER1 | ft -AutoSize
# .\get-Ipdetails.ps1 -computerName SERVER1,SERVER2 | ft -AutoSize


[cmdletbinding()]
param (
 [parameter(ValueFromPipeline=$true,ValueFromPipelineByPropertyName=$true)]
    [string[]]$ComputerName = $env:computername
)
 
begin {}
process {

 foreach ($Computer in $ComputerName) {
  if(Test-Connection -ComputerName $Computer -Count 1 -ea 0) {
   try {
    $Networks = Get-WmiObject Win32_NetworkAdapterConfiguration -ComputerName $Computer -EA Stop | ? {$_.IPEnabled}
   } catch {
        Write-Warning "Error occurred while querying $computer."
        Continue
   }
   foreach ($Network in $Networks) {
    $IPAddress  = $Network.IpAddress[0]
    $SubnetMask  = $Network.IPSubnet[0]
    $DefaultGateway = $Network.DefaultIPGateway
    $DNSServers  = $Network.DNSServerSearchOrder
    $WINS1 = $Network.WINSPrimaryServer
    $WINS2 = $Network.WINSSecondaryServer   
    $WINS = @($WINS1,$WINS2)         
    $IsDHCPEnabled = $false
    If($network.DHCPEnabled) {
     $IsDHCPEnabled = $true
    }
    $MACAddress  = $Network.MACAddress
    $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 -join ",")      
    $OutputObj | Add-Member -MemberType NoteProperty -Name IsDHCPEnabled -Value $IsDHCPEnabled
    $OutputObj | Add-Member -MemberType NoteProperty -Name DNSServers -Value ($DNSServers -join ",")     
    $OutputObj | Add-Member -MemberType NoteProperty -Name WINSServers -Value ($WINS -join ",")        
    $OutputObj | Add-Member -MemberType NoteProperty -Name MACAddress -Value $MACAddress
    $OutputObj
   }
  }
 }
}
 
end {}


1 Comment

WINDA EKA SAMODRA · July 7, 2019 at 6:24 AM

Why i got an error when i use that script?

Leave a Reply to WINDA EKA SAMODRA Cancel reply

Avatar placeholder

Your email address will not be published. Required fields are marked *