From e63b3d65a009b528ca2b639cc7d82d2d5374d7c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Bere=C5=BCa=C5=84ski?= Date: Sat, 5 Jun 2021 23:33:26 +0200 Subject: [PATCH] xVMNetworkAdapter: Fix Get- failing for a ManagementOS adapter The Get-NetworkInformation function does not work for a ManagementOS adapter and should not be called in that code path in Get-TargetResource. --- CHANGELOG.md | 2 ++ .../MSFT_xVMNetworkAdapter.psm1 | 12 ++++++------ 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 24c389b..96fbc84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,8 @@ For older change log history see the [historic changelog](HISTORIC_CHANGELOG.md) - Fixed VMName property in example. - xVMNetworkAdapter - Fixed MacAddress sample data. + - Fixed Get-TargetResource failing for a ManagementOS adapter while trying + to obtain guest IP settings. - xVMSwitch - Correctly return the state as `$true` or `$false` depending on the `Ensure` property when the switch does not exist. diff --git a/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 b/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 index d1ed7ae..3bffa38 100644 --- a/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 +++ b/source/DSCResources/MSFT_xVMNetworkAdapter/MSFT_xVMNetworkAdapter.psm1 @@ -83,13 +83,13 @@ function Get-TargetResource { $configuration.Add('MacAddress', $netAdapter.MacAddress) $configuration.Add('DynamicMacAddress', $netAdapter.DynamicMacAddressEnabled) - } - $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name - if ($networkInfo) - { - $item = New-CimInstance -ClassName MSFT_xNetworkSettings -Property $networkInfo -Namespace root/microsoft/windows/desiredstateconfiguration -ClientOnly - $configuration.Add('NetworkSetting', $item) + $networkInfo = Get-NetworkInformation -VMName $VMName -Name $Name + if ($networkInfo) + { + $item = New-CimInstance -ClassName MSFT_xNetworkSettings -Property $networkInfo -Namespace root/microsoft/windows/desiredstateconfiguration -ClientOnly + $configuration.Add('NetworkSetting', $item) + } } $configuration.Add('Ensure', 'Present')