New-M365DSCReportFromConfiguration does not accept exported config
Description of the issue
Hi All, I'm new to this but have successfully connected to my test tenant using
cert auth and have exported the config of Intune using Export-M365DSCConfiguration. I am now trying to create a report from that (HTML) using
New-M365DSCReportFromConfiguration -Type HTML -ConfigurationPath C:\Temp\M365TenantConfig.ps1 -OutputPath C:\Temp -Verbose
But get the below error
Error parsing configuration: At line:106 char:37
- M365TenantConfig -ConfigurationData .\ConfigurationData.psd1
-
~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '.\ConfigurationData.psd1' in expression or statement. At C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.20\Modules\DSCParser.psm1:490 char:9
-
throw "$($errorPrefix)Error parsing configuration: $parseErro ... -
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~- CategoryInfo : OperationStopped: (Error parsing c...n or statement.:String) [], RuntimeException
- FullyQualifiedErrorId : Error parsing configuration: At line:106 char:37
- M365TenantConfig -ConfigurationData .\ConfigurationData.psd1
-
~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '.\ConfigurationData.psd1' in expression or statement.
attached is the contents of the ConfigurationData.psd1
Any ides where I am going wrong?
Microsoft 365 DSC Version
1.25.709.1
Which workloads are affected
Intune
The DSC configuration
Verbose logs showing the problem
Error parsing configuration: At line:106 char:37
+ M365TenantConfig -ConfigurationData .\ConfigurationData.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '.\ConfigurationData.psd1' in expression or statement.
At C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.20\Modules\DSCParser.psm1:490 char:9
+ throw "$($errorPrefix)Error parsing configuration: $parseErro ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : OperationStopped: (Error parsing c...n or statement.:String) [], RuntimeException
+ FullyQualifiedErrorId : Error parsing configuration: At line:106 char:37
+ M365TenantConfig -ConfigurationData .\ConfigurationData.psd1
+ ~~~~~~~~~~~~~~~~~~~~~~~~
Unexpected token '.\ConfigurationData.psd1' in expression or statement.
Environment Information + PowerShell Version
OsName : Microsoft Windows 11 Enterprise
OsOperatingSystemSKU : EnterpriseEdition
OsArchitecture : 64-bit
WindowsVersion : 2009
WindowsBuildLabEx : 26100.1.amd64fre.ge_release.240331-1435
OsLanguage : en-GB
OsMuiLanguages : {en-GB}
Key : PSVersion
Value : 5.1.26100.4202
Name : PSVersion
Key : PSEdition
Value : Desktop
Name : PSEdition
Key : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0...}
Name : PSCompatibleVersions
Key : BuildVersion
Value : 10.0.26100.4202
Name : BuildVersion
Key : CLRVersion
Value : 4.0.30319.42000
Name : CLRVersion
Key : WSManStackVersion
Value : 3.0
Name : WSManStackVersion
Key : PSRemotingProtocolVersion
Value : 2.3
Name : PSRemotingProtocolVersion
Key : SerializationVersion
Value : 1.1.0.1
Name : SerializationVersion
This happens if you do not name your configuration with the "-ConfigurationName" parameter during Export-M365DSCConfiguration. The default name is "Configuration" which also the keyword for PSDesiredStateConfiguration. If you name it something different like e.g. "Test_Export" it should work.
This is a bug that has been around for some time if I recall correctly.
Thank you, I am now running the below but the files still seem to export with same default names
Exporting resources using certificate
Export-M365DSCConfiguration -Components @("AADAuthenticationMethodPolicy") -ConfigurationName "Test_Export" -ApplicationId $ApplicationId -CertificateThumbprint $CertificateThumbprint -TenantId $TenantId -Path 'C:\Temp'
Hi, similar issue here:
I'm running the command Export-M365DSCConfiguration with App-ID and App-Secret, targeted on Intune-Settings, Export works fine but when I try to run New-M365DSCReportFromConfiguration I get a lot of error messages like the one below. What I tried:
- Updating M365 DSC Module
- Updating Dependencies
- Uninstalling Outdated Dependencies
- winrm quickconfig
- provided a configuration-name and a filename for the export
- Tried PS 5.1 and 7.5.1 and 7.5.2 both with evelated priviledges
The error occurs several times, then the shell seems like it crashed and there is no more progress.
$typeStaticMethods = [] | gm - ...
+ ~
Der Typname nach "[" fehlt.
In C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.20\Modules\DSCParser.psm1:400 Zeichen:29
+ ... Invoke-Expression -Command $scriptBlock | Out-N ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : ParserError: (:) [Invoke-Expression], ParseException
+ FullyQualifiedErrorId : MissingTypename,Microsoft.PowerShell.Commands.InvokeExpressionCommand
Thank you, I am now running the below but the files still seem to export with same default names
# Exporting resources using certificate Export-M365DSCConfiguration -Components @("AADAuthenticationMethodPolicy") -ConfigurationName "Test_Export" -ApplicationId $ApplicationId -CertificateThumbprint $CertificateThumbprint -TenantId $TenantId -Path 'C:\Temp'
The issue comes from some strange PowerShell internal behaviour, where if you once stop the execution of New-M365DSCReportFromConfiguration (or to be more precise: processing of the M365TenantConfig.ps1 file), you can't execute the command again and have to retry it in a new PowerShell session.
As for the other errors, please try it in an elevated Windows PowerShell prompt and see if there are any issues there. If there are, also make sure that no Defender or antivirus configuration blocks anything - We've seen instances where the Microsoft Defender blocks access to CIM / WMI information, which leads to above errors.
Hi, I re-launched the powershell session and have gotten a little bit further but am now hit with the below error. Any thoughts?
Hi, I re-launched the powershell session and have gotten a little bit further but am now hit with the below error. Any thoughts?
![]()
This most likely happens because the ExecutionPolicy is not set to RemoteSigned or Unrestricted. To quote the documentation:
"PowerShell Execution Policy Microsoft365DSC consists of its own module and various PowerShell submodules. Allowing scripts to run is necessary for the successful execution of the functions. The command Get-ExecutionPolicy retrieves the current execution policy. Usually, it is enough if the value is set to RemoteSigned. If you encounter issues while loading scripts, set it to Unrestricted: Set-ExecutionPolicy -ExecutionPolicy Unrestricted"
(https://microsoft365dsc.com/user-guide/get-started/prerequisites/#powershell-execution-policy)
I had the execution policy set as unrestricted but noticed that it always seems to fail when it gets to the 'IntuneDeviceConfigurationCustomPolicyWindows10' piece so for the sake of testing I ran another export just selecting 'IntuneDeviceConfigurationPlatformScriptWindows' and re-ran the 'New-M365DSCReportFromConfiguration' command and it has successfully created it. So it looks to be either something to do with the way its reading the 'IntuneDeviceConfigurationCustomPolicyWindows10' or a particular policy within it that is throwing a spanner in the works
@RobCollinsonCloud Did you already execute it outside of PowerShell ISE, just in a regular Terminal session? It's possible that the ISE doesn't handle a couple of things well (we've already had such things the past).
Just tried again using Terminal but still gets stuck at the same point
PS C:\Windows\System32> Set-ExecutionPolicy Unrestricted PS C:\Windows\System32> New-M365DSCReportFromConfiguration -Type HTML -ConfigurationPath C:\Temp\M365TenantConfig.ps1 -OutputPath C:\Temp\M365Report.html -Verbose
@RobCollinsonCloud Can you share the specific configuration that's failing for you? Maybe I can find something why it's not working.
For now, please try the following statement in an elevated Windows PowerShell session:
$InvokeParams = @{
Name = "IntuneSettingCatalogCustomPolicyWindows10"
Method = 'Get'
Property = @{
'dummyValue' = 'dummyValue'
}
ModuleName = @{
ModuleName = "Microsoft365DSC"
ModuleVersion = "<version of M365DSC that you have installed>"
}
ErrorAction = 'Stop'
}
Invoke-DscResource @InvokeParams # Ignore any error that mentions "dummyValue" is not a valid parameter
$cimInstanceNames = @(
"MSFT_DeviceManagementConfigurationPolicyAssignments"
"MSFT_MicrosoftGraphDeviceManagementConfigurationPolicyTemplateReference"
"MSFT_MicrosoftGraphDeviceManagementConfigurationSetting"
"MSFT_MicrosoftGraphDeviceManagementConfigurationSettingInstance"
"MSFT_MicrosoftGraphDeviceManagementConfigurationSettingInstanceTemplateReference"
"MSFT_MicrosoftGraphDeviceManagementConfigurationChoiceSettingValue"
"MSFT_MicrosoftGraphDeviceManagementConfigurationSettingValueTemplateReference"
"MSFT_MicrosoftGraphDeviceManagementConfigurationGroupSettingValue"
"MSFT_MicrosoftGraphDeviceManagementConfigurationSimpleSettingValue"
"MSFT_IntuneSettingCatalogCustomPolicyWindows10"
)
foreach ($cimInstanceName in $cimInstanceNames) {
$CimInstance = Get-CimClass -ClassName $cimInstanceName `
-Namespace 'ROOT/Microsoft/Windows/DesiredStateConfiguration' `
-ErrorAction SilentlyContinue
}
This will pretty much do the same thing as what the DSCParser does. It checks the available classes of the module (in your case the affected resource is IntuneSettingCatalogCustomPolicyWindows10), and try fetching the information. Let me know how that went.
Sorry for the late reply I have been on holiday, Copied your script and ran it with the below results
Happy to send the exported config privately if there is a way of doing that?
@RobCollinsonCloud You actually have to fill in the placeholder I put in the version field, otherwise it won't work 👀 E.g. 1.25.723.2 (or the latest version 1.25.730.1).
If you want to and you're comfortable with, you can share it over on LinkedIn (see my profile for a link to my account) - there is no way of having a private conversion on GitHub.
My bad
@RobCollinsonCloud @FabienTschanz fixed that here #6352, please try with the latest version.
Updated to the latest version and that seems to have fixed it, thanks guys
# Exporting resources using certificate
Export-M365DSCConfiguration -Components @("AADAuthenticationMethodPolicy") -ConfigurationName "Test_Export" -ApplicationId $ApplicationId -CertificateThumbprint $CertificateThumbprint -TenantId $TenantId -Path 'C:\Temp'