top of page

PowerShell - Get IP Details Local

  • Writer: Jon Boyette
    Jon Boyette
  • Sep 27, 2022
  • 1 min read

Save as a .ps1 and get network config details to screen.

[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 {}


 
 
 

Recent Posts

See All
PowerShell - List All Domain SPNs

Save as same List_ALL_SPNs.ps1 or similar, this LDap calls the Domain for all Service Principal names and accounts related #Build LDAP...

 
 
 
PowerShell - Start-Monitoring

This is a great script used to Monitor and Email if a server is up or down, once ran, and smtp and from address is set, then run:...

 
 
 

Comments


Post: Blog2 Post
  • Facebook
  • Twitter
  • LinkedIn

©2022 by Boyette Technical Services. Proudly created with Wix.com

bottom of page