-
Notifications
You must be signed in to change notification settings - Fork 523
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IntuneDeviceConfigurationAdministrativeTemplatePolicyWindows10: "Cannot bind argument to parameter 'ReferenceObject' because it is null." when deploying #3355
Comments
Thanks, for the details - I'll try to reproduce the error and revert back asap |
Looking at the logs it looks like it's failing here Line 461 in 64d3af5
This is because the assignment on L458 is $null, maybe a check is in order before assuming it has a non-null value? [Array]$currentDefinitionValues = $currentInstance.DefinitionValues |
thanks @ricmestre : I've used a compare-object to compare 2 arrays of Id but it doesn't support $null - replacing $null by @() should do the trick |
Thank you for your assistance with this. Steps take:
I can't spot what's different between the successfully deployed policy and the others. M365TenantConfig.ps1 File
Resulting .mof file
Output when deploying
|
@William-Francillette Hi, the fix for this here was not correct, you may compare empty arrays but not empty/null strings. My initial thinking was that you would insert the condition not only to make the assignment but to also insert the compare there, by leaving it in the same place the error is still present. PS C:\> $currentDefinitionValues = @{}
PS C:\> $currentDefinitionValues.Id = $null
PS C:\> $targetDefinitionValues = @{}
PS C:\> $targetDefinitionValues.Id = New-Guid
PS C:\> $comparedDefinitionValues = Compare-Object `
>> -ReferenceObject ($currentDefinitionValues.Id) `
>> -DifferenceObject ($targetDefinitionValues.Id) `
>> -IncludeEqual
Compare-Object : Cannot bind argument to parameter 'ReferenceObject' because it is null.
At line:2 char:30
+ -ReferenceObject ($currentDefinitionValues.Id) `
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidData: (:) [Compare-Object], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CompareObjectCommand Therefore I'd say if $currentDefinitionValues is null but $targetDefinitionValues is not then all definitions should be added, if it's the opposite they should all be removed and only call the compare if they are both not null. Am I correct? |
Untested, but probably something similar like this: # [...] Starting on line 469 instead of calling Compare-Object
if ($null -ne $currentDefinitionValues)
{
if ($null -ne $targetDefinitionValues)
{
$comparedDefinitionValues = Compare-Object `
-ReferenceObject ($currentDefinitionValues.Id) `
-DifferenceObject ($targetDefinitionValues.Id) `
-IncludeEqual
$definitionValuesToAdd = ($comparedDefinitionValues | Where-Object -FilterScript { $_.SideIndicator -eq '=>' }).InputObject
$definitionValuesToRemove = ($comparedDefinitionValues | Where-Object -FilterScript { $_.SideIndicator -eq '<=' }).InputObject
$definitionValuesToCheck = ($comparedDefinitionValues | Where-Object -FilterScript { $_.SideIndicator -eq '==' }).InputObject
}
else
{
$definitionValuesToAdd = $null
$definitionValuesToRemove = $currentDefinitionValues
$definitionValuesToCheck = $null
}
}
else
{
if ($null -ne $targetDefinitionValues)
{
$definitionValuesToAdd = $targetDefinitionValues
$definitionValuesToRemove = $null
$definitionValuesToCheck = $null
}
else
{
$definitionValuesToAdd = $null
$definitionValuesToRemove = $null
$definitionValuesToCheck = $null
}
}
# [...] code in between
if ($null -ne $definitionValuesToAdd -or $null -ne $definitionValuesToRemove -or $null -ne $definitionValuesToCheck)
{
Update-DeviceConfigurationGroupPolicyDefinitionValue `
-DeviceConfigurationPolicyId $currentInstance.Id `
-DefinitionValueToAdd $formattedDefinitionValuesToAdd `
-DefinitionValueToUpdate $formattedDefinitionValuesToUpdate `
-DefinitionValueToRemove $definitionValuesToRemove
} |
I'll have a look and do more test in the evening after work this evening - I should be able to raise a PR tonight hopefully - it's only an issue with managing the compare-object properly |
There was more work than planned but that should be all fix with #3377 Thanks |
Details of the scenario you tried and the problem that is occurring
Configuration from a tenancy has been exported for deployment to another tenancy via Start-DscConfiguration.
Steps taken:
The policy is created in the target tenancy, but no settings are added:
Note that this occurs regardless of trying to deploy the IntuneDeviceConfigurationAdministrativeTemplatePolicyWindows10 by themselves, or as part of a configuration with other resources (the other resources deploy successfully, only IntuneDeviceConfigurationAdministrativeTemplatePolicyWindows10 fails.
Verbose logs showing the problem
Suggested solution to the issue
Unknown
The DSC configuration that is used to reproduce the issue (as detailed as possible)
M365TenantConfig.ps1 File:
Resulting .mof file:
The operating system the target node is running
OsName : Microsoft Windows Server 2019 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture : 64-bit
WindowsVersion : 1809
WindowsBuildLabEx : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage : en-US
OsMuiLanguages : {en-US}
Version of the DSC module that was used ('dev' if using current dev branch)
1.23.517.1
The text was updated successfully, but these errors were encountered: