Last active
November 1, 2017 03:35
-
-
Save GavinEke/1c67ee8c68e9251e026b190f4a64ffee to your computer and use it in GitHub Desktop.
Example Polyfill, for text parsing example please look at previous versions
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
If (-not (Get-Command Get-NetAdapter -ErrorAction SilentlyContinue)) { | |
Function global:Get-NetAdapter { | |
Begin { | |
$x = Get-WmiObject -Class Win32_NetworkAdapter -Filter 'NetEnabled=true' | |
} | |
Process { | |
ForEach ($Item in $x) { | |
[PSCustomObject]@{ | |
InterfaceName = $Item.Name | |
InterfaceDescription = $Item.Description | |
InterfaceIndex = $Item.InterfaceIndex | |
Status = 'Up' | |
MACAddress = $Item.MACAddress.Replace(':','-') | |
LinkSpeed = $Item.Speed | |
} | |
} | |
} | |
End {} | |
End {} | |
} | |
} | |
If (-not (Get-Command Get-NetIPAddress -ErrorAction SilentlyContinue)) { | |
Function global:Get-NetIPAddress { | |
Begin { | |
$x = Get-WmiObject -Class Win32_NetworkAdapterConfiguration -Filter 'IPEnabled=true' | |
[regex]$IPv4Match = '((1?\d\d?|2[0-4]\d|25[0-5])\.){3}(1?\d\d?|2[0-4]\d|25[0-5])' | |
[regex]$IPv6Match = '\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f]{1,4}){0,4}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:))|(:(((:[0-9A-Fa-f]{1,4}){1,7})|((:[0-9A-Fa-f]{1,4}){0,5}:((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])(\.(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9]?[0-9])){3}))|:)))(%.+)?\s*' | |
} | |
Process { | |
ForEach ($Item in $x) { | |
#IPv4 | |
If ($Item.IPAddress -match $IPv4Match) { | |
[PSCustomObject]@{ | |
IPAddress = [string]($Item.IPAddress -match $IPv4Match) | |
InterfaceIndex = $Item.InterfaceIndex | |
InterfaceAlias = $Item.Description | |
AddressFamily = 'IPv4' | |
} | |
} | |
#IPv6 | |
If ($Item.IPAddress -match $IPv6Match) { | |
[PSCustomObject]@{ | |
IPAddress = [string]($Item.IPAddress -match $IPv6Match) | |
InterfaceIndex = $Item.InterfaceIndex | |
InterfaceAlias = $Item.Description | |
AddressFamily = 'IPv6' | |
} | |
} | |
} | |
} | |
End {} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment