Last active
May 15, 2019 15:02
-
-
Save gomibushi/0c628d0adc9790e17052f04de96f39a8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# .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 | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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! :)