Export-M365DSCConfiguration fails with incorrect location of destination file
Description of the issue
Export-M365DSCConfiguration fails with incorrect path
Microsoft 365 DSC Version
1.25.1001.1
Which workloads are affected
Azure Active Directory (Entra ID)
The DSC configuration
NA
This is related to changes in the modules, not the config
Verbose logs showing the problem
Export-M365DSCConfiguration -Components @("AADConditionalAccessPolicy","AADNamedLocationPolicy","AADAuthenticationMethodPolicyFido2") -ApplicationId $(AppIDTEST) -CertificateThumbprint $Thumbprint -TenantId $(TenantIDtst) -Path 'Export-Test'
Fails with double foldername in the output:
Exporting Microsoft 365 configuration for Components: AADConditionalAccessPolicy, AADNamedLocationPolicy, AADAuthenticationMethodPolicyFido2
Directory "Export-Test" doesn't exist; creating...
...
⌛ Export took {125 seconds} for {67 instances}
Out-File : Could not find a part of the path 'D:\a\1\s\Export-Test\Export-Test\M365TenantConfig.ps1'.
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.1001.1\Modules\M365DSCReverse.psm1:935 char:34
+ $DSCContent.ToString() | Out-File $outputDSCFile
+ ~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OpenError: (:) [Out-File], DirectoryNotFoundException
+ FullyQualifiedErrorId : FileOpenFailure,Microsoft.PowerShell.Commands.OutFileCommand
Environment Information + PowerShell Version
I have the same issue with version 1.25.1001.1, the provided relative path seems to be doubled in the output path.
My export command:
Export-M365DSCConfiguration -Components @("AADGroup") -ApplicationId $Params.ApplicationId -CertificateThumbprint $params.CertificateThumbprint -TenantId $params.TenantId -FileName "EXPORT_AADGroups.ps1" -Path ".\M365DSC\PipelineExports"
The error from pipeline:
I checked the M365DSCReverse.ps1 and i think the problem is with relative paths like ".\M365DSC\PipelineExports" and the "Push-Location -Path $OutputDSCPath" in line 159. Since the location of the PS runtime already is in the export path 'D:\a\1\s\M365DSC\PipelineExports' but still wants to export to ".\M365DSC\PipelineExports" resulting in the absolute path 'D:\a\1\s\M365DSC\PipelineExports\M365DSC\PipelineExports\EXPORT_AADGroups.ps1' which cannot be found
Version 1.25.910.1 works fine in that regard, so i currently using this until a fix is provided
A workaround is also to not provide a relative path but rather the absolut path like:
(Join-path -Path (Get-Location) -ChildPath "M365DSC\PipelineExports")
I have the same issue with version 1.25.1001.1, the provided relative path seems to be doubled in the output path.
My export command:
Export-M365DSCConfiguration -Components @("AADGroup") -ApplicationId $Params.ApplicationId -CertificateThumbprint $params.CertificateThumbprint -TenantId $params.TenantId -FileName "EXPORT_AADGroups.ps1" -Path ".\M365DSC\PipelineExports"The error from pipeline:
I checked the M365DSCReverse.ps1 and i think the problem is with relative paths like ".\M365DSC\PipelineExports" and the "Push-Location -Path $OutputDSCPath" in line 159. Since the location of the PS runtime already is in the export path 'D:\a\1\s\M365DSC\PipelineExports' but still wants to export to ".\M365DSC\PipelineExports" resulting in the absolute path 'D:\a\1\s\M365DSC\PipelineExports\M365DSC\PipelineExports\EXPORT_AADGroups.ps1' which cannot be found
Version 1.25.910.1 works fine in that regard, so i currently using this until a fix is provided
you are right and the fix is already in a PR : fix for export config location #6581
I checked the M365DSCReverse.ps1 and i think the problem is with relative paths like ".\M365DSC\PipelineExports" and the "Push-Location -Path $OutputDSCPath" in line 159. Since the location of the PS runtime already is in the export path 'D:\a\1\s\M365DSC\PipelineExports' but still wants to export to ".\M365DSC\PipelineExports" resulting in the absolute path 'D:\a\1\s\M365DSC\PipelineExports\M365DSC\PipelineExports\EXPORT_AADGroups.ps1' which cannot be found