Skip to content

Instantly share code, notes, and snippets.

@gomibushi
Last active May 15, 2019 15:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gomibushi/0c628d0adc9790e17052f04de96f39a8 to your computer and use it in GitHub Desktop.
Save gomibushi/0c628d0adc9790e17052f04de96f39a8 to your computer and use it in GitHub Desktop.
# .SYNOPSIS
# Get-NetIPServerInfo gets the IP configuration of all Computers passed as parameters
# .DESCRIPTION
# Uses Test-Connection to check if the server is powered on and reachable.
# .EXAMPLE
# Get-NetIPServerInfo -Computername server1, server2
#.EXAMPLE
# 'server1', 'server2' | Get-NetIPServerInfo | Format-Table
# .NOTES
# Author: Patrick Gruenauer
# Web: https://sid-500.com
#
# Made to accept computernames as parameters by Pål Røtnes
# gomibushi@gmail.com
function Get-NetIPServerInfo {
[CmdletBinding()]
Param (
[parameter(Mandatory=$true,ValueFromPipeline=$true)]
[Array]$Computername
)
Process
{
foreach ($c in $Computername)
{
$i=Invoke-Command -ComputerName $c -ScriptBlock {
Get-NetIPConfiguration |
Select-Object `
-Property InterfaceAlias,Ipv4Address,DNSServer
Get-NetRoute -DestinationPrefix '0.0.0.0/0' |
Select-Object -ExpandProperty NextHop
}
$result = $null
$result +=New-Object -TypeName PSCustomObject -Property ([ordered]@{
'Server'= $c
'Interface' = $i.InterfaceAlias -join ','
'IPv4Address' = $i.Ipv4Address.IPAddress -join ','
'Gateway' = $i | Select-Object -Last 1
'DNSServer' = ($i.DNSServer |
Select-Object -ExpandProperty ServerAddresses) -join ','
})
$result
}
}
}
@gomibushi
Copy link
Author

You can find the original script here:
https://sid-500.com/2018/10/26/retrieve-the-ip-configuration-of-all-windows-servers-with-get-netipserverinfo/
Thanks for the difficult code! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment