Last active
September 1, 2019 08:44
-
-
Save rezarahimian/f00ce16b81031b23be2ef78d526a6680 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
[CmdletBinding()] | |
PARAM() | |
# Returns IP address of a network adapter | |
function Get-IPInfo() | |
{ | |
[CmdletBinding()] | |
PARAM( | |
[Parameter(Mandatory=$True)] | |
[ValidateSet('IPv4','IPv6','IPv6LinkLocal')] | |
[String] $IPVersion, | |
[Parameter(Mandatory=$True)] | |
[String] $Interface | |
) | |
Write-Debug -Message ('[*] Getting "{0}" of "{1}"...' -f $IPVersion, $Interface) | |
$Property = ($IPVersion+'Address') | |
Get-NetIPConfiguration | Where-Object { $_.InterfaceDescription -eq $Interface } | | |
Select -Property $Property | Select-Object -Property ` | |
@{Name='IPVersion'; Expression={$IPVersion}}, | |
@{Name='IPAddress'; Expression={$_.$Property}}, | |
@{Name='Interface'; Expression={$Interface}} | |
} | |
# Main | |
$DebugPreference = 'Continue' | |
$IPInfo = @() | |
$Interfaces = Get-NetAdapter | Where-Object {$_.Status -eq 'Up'} | |
$NumOfInterfaces = ($Interfaces | Measure-Object).Count | |
Write-Debug -Message ("[1] Identified {0} network adapter(s)..." -f $NumOfInterfaces) | |
ForEach($Interface in $Interfaces) | |
{ | |
$InterfaceName = $Interface.InterfaceDescription | |
Write-Debug -Message ('[2] $IPInfo type is "{0}"...' -f $IPInfo.GetType()) | |
$IPInfo = Get-IPInfo -IPVersion IPv4 -Interface $InterfaceName | |
Write-Debug -Message ('[3] $IPInfo type is "{0}"...' -f $IPInfo.GetType()) | |
$IPInfo += Get-IPInfo -IPVersion IPv6 -Interface $InterfaceName | |
$IPInfo += Get-IPInfo -IPVersion IPv6LinkLocal -Interface $InterfaceName | |
} | |
$IPInfo | |
$DebugPreference = 'SilentlyContinue' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment