Merge pull request #6397 from jborean93/hyper-v-ip-bsd
Check if hyper-v addresses is an array before slicing it
This commit is contained in:
commit
0d63cf7bc4
|
@ -1009,7 +1009,11 @@ param([string]$mac, [int]$addressIndex)
|
||||||
try {
|
try {
|
||||||
$vm = Hyper-V\Get-VM | ?{$_.NetworkAdapters.MacAddress -eq $mac}
|
$vm = Hyper-V\Get-VM | ?{$_.NetworkAdapters.MacAddress -eq $mac}
|
||||||
if ($vm.NetworkAdapters.IpAddresses) {
|
if ($vm.NetworkAdapters.IpAddresses) {
|
||||||
$ip = $vm.NetworkAdapters.IpAddresses[$addressIndex]
|
$ipAddresses = $vm.NetworkAdapters.IPAddresses
|
||||||
|
if ($ipAddresses -isnot [array]) {
|
||||||
|
$ipAddresses = @($ipAddresses)
|
||||||
|
}
|
||||||
|
$ip = $ipAddresses[$addressIndex]
|
||||||
} else {
|
} else {
|
||||||
$vm_info = Get-CimInstance -ClassName Msvm_ComputerSystem -Namespace root\virtualization\v2 -Filter "ElementName='$($vm.Name)'"
|
$vm_info = Get-CimInstance -ClassName Msvm_ComputerSystem -Namespace root\virtualization\v2 -Filter "ElementName='$($vm.Name)'"
|
||||||
$ip_details = (Get-CimAssociatedInstance -InputObject $vm_info -ResultClassName Msvm_KvpExchangeComponent).GuestIntrinsicExchangeItems | %{ [xml]$_ } | ?{ $_.SelectSingleNode("/INSTANCE/PROPERTY[@NAME='Name']/VALUE[child::text()='NetworkAddressIPv4']") }
|
$ip_details = (Get-CimAssociatedInstance -InputObject $vm_info -ResultClassName Msvm_KvpExchangeComponent).GuestIntrinsicExchangeItems | %{ [xml]$_ } | ?{ $_.SelectSingleNode("/INSTANCE/PROPERTY[@NAME='Name']/VALUE[child::text()='NetworkAddressIPv4']") }
|
||||||
|
|
Loading…
Reference in New Issue