简体   繁体   中英

In Powershell, how can I correctly use Get-CimInstance to retrieve the IPV6 addresses of respective computers?

I have tried this,

  Get-CimInstance Win32_NetworkAdapterConfiguration -ComputerName $computerName | Where-Object { $_.AddressFamily -eq 'IPv6' }

as well as this,

Get-NetIPAddress -ComputerName $computerName | Where-Object {$_.AddressFamily -eq 'IPV6'}

but nothing seems to be working for me to use Get-CimInstance to correctly obtain the IPV6 addresses. I just get errors related to parameters.

Your first example, that CIMInstance does not contain a property called AddressFamily .

Your second example is a perfectly valid command.

Get-NetIPAddress -ComputerName $computerName | Where-Object {$_.AddressFamily -eq 'IPV6'}

Are you sure your computerName isn't blank, or unreachable (perms/network/psremote)?

Invoke-Command -ComputerName "DellXPS8700" -ScriptBlock {
(Get-NetIPAddress  | Where-Object {$_.AddressFamily -eq 'IPV6'}) |
 Select-Object InterfaceAlias, IPAddress | FT }

Sample Output:

InterfaceAlias                 IPAddress                              
--------------                 ---------                              
Loopback Pseudo-Interface 1    ::1                                    
Ethernet                       fe80::59be:16e2:a647:9c73%10           
Ethernet                       2606:a000:1321:425e:59be:16e2:a647:9c73
Ethernet                       2606:a000:1321:425e:2413:c2f5:cb57:6252
Bluetooth Network Connection 2 fe80::9037:3e88:9c22:8ce2%3            

I figured the addresses weren't much help w/o reference to the adapters.

Of course you can put this in a loop to get values for a whole raft of machines.

HTH

Ok, here's a workable solution using Get-CimInstance.

$x = (Get-CimInstance Win32_NetworkAdapterConfiguration -ComputerName "DellXPS8700").IPAddress
For ( $Cntr = 0 ; $Cntr -lt $x.Count; $cntr++) {
   If ($Null -ne $x[$($Cntr)] ) {
     If ($x[$($Cntr)].IndexOf(":") -ne -1) {
       "$($x[$($Cntr)])"
     }
   }
}

Output:

fe80::59be:16e2:a647:9c73
2606:a000:1321:425e:2413:c2f5:cb57:6252
2606:a000:1321:425e:59be:16e2:a647:9c73

HTH

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM