# string converts to ConsoleColor PS> [ConsoleColor]'red' Red
# string converts to System.Windows.Media.Color PS> [System.Windows.Media.Color]'red'
ColorContext : A : 255 R : 255 G : 0 B : 0 ScA : 1 ScR : 1 ScG : 0 ScB : 0
# ConsoleColor DOES NOT convert to System.Windows.Media.Color PS> [System.Windows.Media.Color][ConsoleColor]'red' Cannot convert value "Red" to type"System.Windows.Media.Color". Error: "Invalid cast from 'System.ConsoleColor' to 'System.Windows.Media.Color'." At line:1 char:1 + [System.Windows.Media.Color][ConsoleColor]'red' + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidArgument: (:) [], RuntimeException + FullyQualifiedErrorId : InvalidCastIConvertible
functionGet-IPAddress { Get-CimInstance-ClassName Win32_NetworkAdapterConfiguration | Where-Object { $_.IPEnabled -eq$true } | # add two new properties for IPv4 and IPv6 at the end Select-Object-Property Description, MacAddress, IPAddress, IPAddressV4, IPAddressV6 | ForEach-Object { # add IP addresses that match the filter to the new properties $_.IPAddressV4 = $_.IPAddress | Where-Object { $_-like'*.*.*.*' } $_.IPAddressV6 = $_.IPAddress | Where-Object { $_-notlike'*.*.*.*' } # return the object $_ } | # remove the property that holds all IP addresses Select-Object-Property Description, MacAddress, IPAddressV4, IPAddressV6 }
Get-IPAddress
结果看起来类似这样:
Description MacAddress IPAddressV4 IPAddressV6
----------- ---------- ----------- -----------
Realtek USB GbE Family Controller #3 00:E0:4C:F4:A9:35 10.4.121.75 fe80::8109:a41e:192b:367