Skip to content
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

Export-M365DSCConfiguration fails if local $Filter variable is defined #3515

Closed
ricmestre opened this issue Jul 27, 2023 · 0 comments · Fixed by #3516 or #3568
Closed

Export-M365DSCConfiguration fails if local $Filter variable is defined #3515

ricmestre opened this issue Jul 27, 2023 · 0 comments · Fixed by #3516 or #3568

Comments

@ricmestre
Copy link
Contributor

Details of the scenario you tried and the problem that is occurring

While testing filtering during exporting it was working fine with the one I chose, then I assigned that filter (hashtable) to a local variable called $Filter, afterwards running the same export it failed even if without using the $Filter variable in the arguments.

$Filter = @{ AADUser = "userPrincipalName eq '[email protected]'" }
Export-M365DSCConfiguration -Credential $creds `
	-Components AADUser `
	-Filters @{ AADUser = "userPrincipalName eq '[email protected]'" } ` # 
	-FileName test.ps1 `
	-Path .\

Verbose logs showing the problem

[...]
Connecting to {MicrosoftGraph}...✅
[1/1] Extracting [AADUser] using {Credentials}...Partial Export file was saved at: C:\Users\ADM_PT~1\AppData\Local\Temp\bd7321ad-b82f-4330-bc65-f359abd99c3b.partial.ps1

Exception calling "Add" with "2" argument(s): "Item has already been added. Key in dictionary: 'Filter'  Key being added: 'Filter'"
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.23.719.1\modules\M365DSCReverse.psm1:612 char:25
+                         $parameters.Add('Filter', $resourceFilter)
+                         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
	+ CategoryInfo          : NotSpecified: (:) [], MethodInvocationException
	+ FullyQualifiedErrorId : ArgumentException

Suggested solution to the issue

This is because the code in M365DSCReverse.psm1 is wrong since it's looking at $Filter variable instead of $Filters in one chunk ($Filter at this point is always $null unless you define it locally), adds Filter to $parameters and then tries to add it again at line 612, if $Filter was defined locally then it fails at that line. In order to fix this the first chunk should be removed and adapt second one.

The DSC configuration that is used to reproduce the issue (as detailed as possible)

N/A

The operating system the target node is running

OsName : Microsoft Windows 10 Enterprise OsOperatingSystemSKU : EnterpriseEdition OsArchitecture : 64-bit WindowsVersion : 2009 WindowsBuildLabEx : 19041.1.amd64fre.vb_release.191206-1406 OsLanguage : en-US OsMuiLanguages : {en-US}

Version of the DSC module that was used ('dev' if using current dev branch)

Dev

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant