在Powershell中,如何正确使用Get-CimInstance检索相应计算机的IPV6地址?



我试过这个,

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

以及这个,

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

但是我似乎没有什么使用 Get-CimInstance 正确获取 IPV6 地址。我只是收到与参数相关的错误。

您的第一个示例,该 CIMInstance 不包含名为AddressFamily的属性。

第二个示例是完全有效的命令。

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

您确定您的computerName不是空白的,或者无法访问(perms/network/psremote(吗?

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

示例输出:

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            

我认为这些地址在没有引用适配器的情况下没有多大帮助。

当然,您可以将其放在一个循环中以获取大量机器的值。

呵呵

好的,这是一个使用 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)])"
}
}
}

输出:

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

呵呵

最新更新