You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Details of the scenario you tried and the problem that is occurring
The Test-DscPropertyState function in the ActiveDirectoryDsc.Common module raises an exception in the following scenarios:
When evaluating an array, but the current value is $null
When evaluating an array, when both values are $null
This is because $null does not have a Get-Type() method and Compare-Object can't take $null as an input.
Verbose logs showing the problem
[-] Should return false when evaluating an array, but the desired value is $null 2ms
RuntimeException: You cannot call a method on a null-valued expression.
at Test-DscPropertyState, \\nas01\data\users\simon\documents\GitHub\X-Guardian\ActiveDirectoryDsc\Modules\ActiveDirectoryDsc.Common\ActiveDirectoryDsc.Common.psm1: line 1806
[-] Should return true when evaluating an array, when both values are $null 3ms
RuntimeException: You cannot call a method on a null-valued expression.
at Test-DscPropertyState, \\nas01\data\users\simon\documents\GitHub\X-Guardian\ActiveDirectoryDsc\Modules\ActiveDirectoryDsc.Common\ActiveDirectoryDsc.Common.psm1: line 1804
Suggested solution to the issue
Add code to Test-DscPropertyState to check $Values.CurrentValue and $Values.DesiredValues against $null.
New Pester Tests Showing the Issues
It 'Should return false when evaluating an array, but the desired value is an empty array' {
$mockValues=@{
CurrentValue=@('1','2')
DesiredValue=@()
}
Test-DscPropertyState-Values $mockValues| Should -BeFalse
}
It 'Should return true when evaluating an array, when both values are $null' {
$mockValues=@{
CurrentValue=$nullDesiredValue=$null
}
Test-DscPropertyState-Values $mockValues-Verbose | Should -BeTrue
}
The operating system the target node is running
OsName : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture : 64-bit
WindowsVersion : 1903
WindowsBuildLabEx : 18362.1.amd64fre.19h1_release.190318-1202
OsLanguage : en-GB
OsMuiLanguages : {en-GB, en-US, th-TH}
Version and build of PowerShell the target node is running
…paring $Null and Arrays (#514)
- Changes to ActiveDirectoryDsc.Common
- Fix `Test-DscPropertyState` Failing when Comparing $Null and Arrays (issue #513).
Details of the scenario you tried and the problem that is occurring
The
Test-DscPropertyState
function in the ActiveDirectoryDsc.Common module raises an exception in the following scenarios:This is because
$null
does not have aGet-Type()
method andCompare-Object
can't take $null as an input.Verbose logs showing the problem
Suggested solution to the issue
Add code to
Test-DscPropertyState
to check$Values.CurrentValue
and$Values.DesiredValues
against $null.New Pester Tests Showing the Issues
The operating system the target node is running
Version and build of PowerShell the target node is running
Version of the DSC module that was used ('dev' if using current dev branch)
dev
The text was updated successfully, but these errors were encountered: