Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

Custom DSC Module causing delta report to fail

Open ssoabx opened this issue 7 months ago • 7 comments

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


ssoabx avatar Apr 13 '26 00:04 ssoabx

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-DSCObject fails while DscResourceInfo is supplied, it retries once without DscResourceInfo.
  • 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.

Shirshaw64p avatar Apr 13 '26 02:04 Shirshaw64p

@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.

FabienTschanz avatar Apr 13 '26 05:04 FabienTschanz

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]

ssoabx avatar Apr 16 '26 13:04 ssoabx

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 avatar Apr 16 '26 13:04 ssoabx

@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.

FabienTschanz avatar Apr 16 '26 13:04 FabienTschanz

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

ssoabx avatar Apr 16 '26 14:04 ssoabx

That's strange, it should have worked regardless. Still glad it worked at the end. Thanks for testing!

FabienTschanz avatar Apr 16 '26 14:04 FabienTschanz