Custom DSC Module causing delta report to fail
Description of the issue
We have a custom DSC module for some additional resources (with specific workflows we need in our environment). With the new DSC update they cause the delta report to fail. If removed form the config the delta report runs fine. I assume this comes from the recent C# rewrite? The specific delta report we are running is the tenant export VS the master config we maintain (before pushing a release). Any chance this can be handled or is this an unsupported/desired scenario?
Microsoft 365 DSC Version
1.26.408.1
Which workloads are affected
other
The DSC configuration
Configuration MasterConfig
{
param (
)
$OrganizationName = $ConfigurationData.NonNodeData.OrganizationName
Import-DscResource -ModuleName 'Microsoft365DSC'
Import-DscResource -ModuleName 'Microsoft365DSCCustomModule'
Node localhost
{
....
}
}
Verbose logs showing the problem
##[warning]ConvertTo-DSCObject : Error parsing DSC configuration: Exception calling "ConvertToDscObject" with "4" argument(s):
##[warning]"The given key was not present in the dictionary."
##[warning]At D:\a\1\s\Modules\Microsoft365DSC\1.26.408.1\Modules\M365DSCReport.psm1:1895 char:22
##[warning]+ $parsedContent = ConvertTo-DSCObject @params
##[warning]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[warning] + CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
##[warning] + FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,ConvertTo-DSCObject
##[warning]Exception calling "ConvertToDscObject" with "4" argument(s): "The given key was not present in the dictionary."
##[warning]At C:\Program Files\WindowsPowerShell\Modules\DSCParser\3.0.0.2\DSCParser.psm1:164 char:13
##[warning]+ $result = [DSCParser.CSharp.DscParser]::ConvertToDscObjec ...
##[warning]+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
##[warning] + CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
##[warning] + FullyQualifiedErrorId : KeyNotFoundException
Environment Information + PowerShell Version
A proposed fix is now available in PR #7059: https://github.com/Microsoft365DSC/Microsoft365DSC/pull/7059
What changed
- In
Initialize-M365DSCReporting, parsing now keeps the existing primary path first. - If
ConvertTo-DSCObjectfails whileDscResourceInfois supplied, it retries once withoutDscResourceInfo. - A warning is emitted with the original parser failure detail before fallback.
Why
This makes delta report parsing more resilient for mixed configurations that include custom DSC resources not represented in the Microsoft365DSC resource metadata map.
The change is intentionally minimal and scoped to report parsing resilience only.
@ssoabx Are you able to share parts of the configuration including the custom DSC resources with me? I'd like to fix the DSCParser so that it allows your kind of DSC resource as well. Sorry about that, was not intended that way. If it worked previously, then it is supposed to work now as well.
Hi Fabien, Thanks for the always fast fixes! I tried to run it with DSCParser 3.0.0.4 but had no luck yet.
Here is a redacted/shortened example with a custom resource. (It's a more general use case for this one but we also have some with integrated workflows into keyvaults or ticket systems which can never be covered through the official one.)
DSC config
Configuration MasterConfig
{
param (
)
$OrganizationName = $ConfigurationData.NonNodeData.OrganizationName
if ($ConfigurationData.NonNodeData.Shortname) {$short=$ConfigurationData.NonNodeData.Shortname}
Else {$short="Org"}
Import-DscResource -ModuleName 'Microsoft365DSC'
Import-DscResource -ModuleName 'Microsoft365DSCCustom'
Node localhost
{
TeamsHoliday "Easter"
{
Name = 'Easter';
ApplicationId = $ConfigurationData.NonNodeData.ApplicationId;
CertificateThumbprint = $ConfigurationData.NonNodeData.CertificateThumbprint;
Ensure = "Present";
TenantId = $OrganizationName;
DateTimeFormat = 'dd-MM-yyyy HH:mm:ss';
DateTimeRange = '
[
{
"Start": "02-04-2026 11:30:00",
"End": "04-04-2026 00:00:00"
},
{
"Start": "06-04-2026 00:00:00",
"End": "07-04-2026 00:00:00"
}
]'
}
}
}
Error with example config:
Convertto-DSCObject -path "C:\temp\deltatest\MasterConfig-sanitized2.ps1"
Convertto-DSCObject : Error parsing DSC configuration: Exception calling "ConvertToDscObject" with "4" argument(s):
"The given key was not present in the dictionary."
At line:1 char:1
+ Convertto-DSCObject -path "C:\temp\deltatest\MasterConfig-sanitized2. ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [Write-Error], WriteErrorException
+ FullyQualifiedErrorId : Microsoft.PowerShell.Commands.WriteErrorException,ConvertTo-DSCObject
Exception calling "ConvertToDscObject" with "4" argument(s): "The given key was not present in the dictionary."
At C:\Program Files\WindowsPowerShell\Modules\DSCParser\3.0.0.4\DSCParser.psm1:160 char:13
+ $result = [DSCParser.CSharp.DscParser]::ConvertToDscObjec ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], ParentContainsErrorRecordException
+ FullyQualifiedErrorId : KeyNotFoundException
"TeamsHolidy" does get listed under Get-DscResourceV2 with it's module.
For the module: [Microsoft365DSCCustom]
- [DSCResources]
- [MSFT_TeamsHoliday]
- Microsoft365DSCCustom.psd1.txt
I reopened powershell a bunch before but it looks like it needed & (Get-Module DSCParser) { $Script:DscResourceCache = $null } to properly reset and it shows a result now. I'll try to test it with the full config again.
@ssoabx Did you update the Manifest.psd1 to target DSCParser 3.0.0.4? If it still points to 3.0.0.2, it won't work because it pre-imports the 3.0.0.2 and ignores 3.0.0.4, even though it is installed.
Yes I did do that. The above error example is even from running ConvertToDscObject directly. I've also double checked that is has the newly compiled binary. Really not sure why it was caching it across sessions (or something else was funky). That said it does create the delta again without aborting so that's great. Thanks
That's strange, it should have worked regardless. Still glad it worked at the end. Thanks for testing!