Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

Exception parsing MOF file '...\MSFT_AADCrossTenantAccessPolicyConfigurationPartner.Schema.mof':The given key was not present in the dictionary..

Open Borgquite opened this issue 8 months ago • 6 comments

Description of the issue

I recently upgraded my install of Microsoft365DSC from version 1.25.903.1 to 1.26.318.1.

I've got composite resources for our server roles, compiling using Windows PowerShell 5.1; one of the composite resources includes various instances of the following Microsoft365DSC resources:

  • AADGroup
  • AADAdministrativeUnit
  • EXODistributionGroup
  • EXOManagementRoleAssignment

I've put some sample configurations below to give you an idea of what's happening, although I can't reproduce this outside of the composite configuration.

When I update the Import-DscResource -ModuleName Microsoft365DSC -ModuleVersion 1.26.318.1 command in the composite resource to the latest version, and try to compile, compliation fails with the following error:

Exception parsing MOF file 'C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.26.318.1\DSCResources\MSFT_AADCrossTenantAccessPolicyConfigurationPartner\MSFT_AADCrossTenantAcce ssPolicyConfigurationPartner.Schema.mof':The given key was not present in the dictionary..                                                                                                 
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ExceptionParsingMOFFile

If I put ModuleVersion back to 1.25.903.1, then the compilation process works perfectly.

Please note that I am not using MSFT_AADCrossTenantAccessPolicyConfigurationPartner in the configuration at all!

Any ideas? I'm stumped!

Microsoft 365 DSC Version

1.26.318.1

Which workloads are affected

other

The DSC configuration

# NB This does not replicate the issue but gives an idea of what the composite resource contains

Configuration Example
{
    Import-DscResource -ModuleName Microsoft365DSC -ModuleVersion 1.26.318.1

    node localhost
    {
        AADAdministrativeUnit 'TestUnit'
        {
            DisplayName                   = 'Test-Unit'
            Description                   = 'Test-Unit1'
            MembershipRule                = "(user.country -eq `"Canada`")"
            MembershipRuleProcessingState = 'On'
            MembershipType                = 'Dynamic'
            ScopedRoleMembers             = @(
                MSFT_MicrosoftGraphScopedRoleMembership
                {
                    RoleName       = 'User Administrator'
                    RoleMemberInfo = MSFT_MicrosoftGraphMember
                    {
                        Identity = "[email protected]"
                        Type     = "User"
                    }
                }
                MSFT_MicrosoftGraphScopedRoleMembership
                {
                    RoleName       = 'User Administrator'
                    RoleMemberInfo = MSFT_MicrosoftGraphMember
                    {
                        Identity = "[email protected]"
                        Type     = "User"
                    }
                }
            )
            ApplicationId                 = $Microsoft365DSCApplicationId
            CertificateThumbprint         = $Microsoft365DSCCertificateThumbprint
            TenantId                      = $Microsoft365DSCOrganization
        }
        AADGroup 'TestM365DynamicGroup'
        {
            DisplayName = "TestM365DynamicGroup"
            MailNickname = "TestM365DynamicGroup"
            GroupTypes = @("Unified", "DynamicMembership")
            MembershipRule = "(user.userPrincipalName -eq `"[email protected]`")"
            MembershipRuleProcessingState = "On"
            SecurityEnabled = $false
            MailEnabled = $true
            IsAssignableToRole = $true
            Visibility = "Private"
            ApplicationId = $Microsoft365DSCApplicationId
            CertificateThumbprint = $Microsoft365DSCCertificateThumbprint
            TenantId = $Microsoft365DSCOrganization
        }
        EXOGroupSettings 'TestM365DynamicGroup'
        {
            DisplayName = "TestM365DynamicGroup"
            AutoSubscribeNewMembers = $true
            WelcomeMessageEnabled = $false
            ApplicationId = $Microsoft365DSCApplicationId
            CertificateThumbprint = $Microsoft365DSCCertificateThumbprint
            TenantId = $Microsoft365DSCOrganization
            DependsOn = "[AADGroup]TestM365DynamicGroup"
        }
        EXODistributionGroup 'TestDG'
        {
            Identity                           = "TestDG"
            Alias                              = "TestDG";
            Name                               = "TestDG";
            PrimarySmtpAddress                 = "[email protected]
            Type = "Security"
            HiddenFromAddressListsEnabled = $true
            ApplicationId                      = $Microsoft365DSCApplicationId
            CertificateThumbprint              = $Microsoft365DSCCertificateThumbprint
            TenantId                           = $Microsoft365DSCOrganization
        }
        EXOManagementRoleAssignment "EXOManagementRoleAssignment"
        {
            Name = "EXO $DomainNameRoot $($tmpExoRole.RoleName) Role"
            Role = "Mail Recipients"
            SecurityGroup = "TestDG"
            ApplicationId = $Microsoft365DSCApplicationId
            CertificateThumbprint = $Microsoft365DSCCertificateThumbprint
            TenantId = $Microsoft365DSCOrganization
        }
    }
}

$cd = @{
    AllNodes = @(
        @{
            NodeName = 'localhost'
            PSDscAllowPlainTextPassword = $true
        }
    )
}

Example -ConfigurationData $cd

Verbose logs showing the problem

Exception parsing MOF file 'C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.26.318.1\DSCResources\MSFT_AADCrossTenantAccessPolicyConfigurationPartner\MSFT_AADCrossTenantAcce ssPolicyConfigurationPartner.Schema.mof':The given key was not present in the dictionary..                                                                                                 
    + CategoryInfo          : ParserError: (:) [], ParseException
    + FullyQualifiedErrorId : ExceptionParsingMOFFile

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, en-US}

Key   : PSVersion
Value : 5.1.26100.7920
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.7920
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

Borgquite avatar Mar 25 '26 17:03 Borgquite

I had the sane error messages when I ran M365* commands multiple times and mixing them with Connect-M365Tenant to execute Powershell comdlets. Restarting the Powershell session fixed it.

1Dimitri avatar Mar 26 '26 08:03 1Dimitri

I'll take a look at that a bit later. Currently in the middle of preparing the next breaking change release. Maybe it is already fixed with that. Will give feedback once tested.

FabienTschanz avatar Mar 26 '26 09:03 FabienTschanz

FYI seems to work fine on 1.26.311.1 (the previous version)

Borgquite avatar Mar 26 '26 12:03 Borgquite

Specifically restoring DSCResources\MSFT_AADCrossTenantAccessPolicyConfigurationPartner from 1.26.311.1 into a 1.26.318.1 installation also works.

Borgquite avatar Mar 26 '26 13:03 Borgquite

Fairly sure this is an issue with the new IdentitySynchronization parameter of AADCrossTenantAccessPolicyConfiguration partner.

This configuration will not compile:

Configuration Example
{
    param(
        [Parameter()]
        [System.String]
        $ApplicationId,

        [Parameter()]
        [System.String]
        $TenantId,

        [Parameter()]
        [System.String]
        $CertificateThumbprint
    )
    Import-DscResource -ModuleName Microsoft365DSC -ModuleVersion 1.26.318.1

    Node localhost
    {
        AADCrossTenantAccessPolicyConfigurationPartner "AADCrossTenantAccessPolicyConfigurationPartner"
        {
            PartnerTenantId              = "e7a80bcf-696e-40ca-8775-a7f85fbb3ebc"; # O365DSC.onmicrosoft.com
            AutomaticUserConsentSettings = MSFT_AADCrossTenantAccessPolicyAutomaticUserConsentSettings {
                InboundAllowed           = $True
                OutboundAllowed          = $True
            };
            B2BCollaborationOutbound     = MSFT_AADCrossTenantAccessPolicyB2BSetting {
                Applications = MSFT_AADCrossTenantAccessPolicyTargetConfiguration{
                    AccessType = 'allowed'
                    Targets    = @(
                        MSFT_AADCrossTenantAccessPolicyTarget{
                            Target     = 'AllApplications'
                            TargetType = 'application'
                        }
                    )
                }
                UsersAndGroups = MSFT_AADCrossTenantAccessPolicyTargetConfiguration{
                    AccessType = 'allowed'
                    Targets    = @(
                        MSFT_AADCrossTenantAccessPolicyTarget{
                            Target     = '68bafe64-f86b-4c4e-b33b-9d3eaa11544b' # Office 365
                            TargetType = 'user'
                        }
                    )
                }
            };
            IdentitySynchronization = MSFT_AADCrossTenantIdentitySyncPolicyPartner {
                GroupSyncInbound = MSFT_AADCrossTenantGroupSyncInbound {
                    IsSyncAllowed = $true
                };
                UserSyncInbound = MSFT_AADCrossTenantUserSyncInbound {
                    IsSyncAllowed = $true
                };
            };
            ApplicationId         = $ApplicationId
            TenantId              = $TenantId
            CertificateThumbprint = $CertificateThumbprint
            Ensure                       = "Present";
        }
    }
}

with the error:

Write-NodeMOFFile : Invalid MOF definition for node 'localhost': Exception calling "ValidateInstanceText" with "1" argument(s): "Undefined property GroupSyncInbound
 At line:71, char:2
 Buffer:
erSyncInbound1ref;
};^
ins
"
At C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules\PSDesiredStateConfiguration\PSDesiredStateConfiguration.psm1:2369 char:21
+ ...             Write-NodeMOFFile $Name $mofNode $Script:NodeInstanceAlia ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [Write-Error], InvalidOperationException
    + FullyQualifiedErrorId : InvalidMOFDefinition,Write-NodeMOFFile

The extra layer of embedded MOF for GroupSyncInbound and UserSyncInbound seems unnecessary? Since the classes MSFT_AADCrossTenantGroupSyncInbound and MSFT_AADCrossTenantUserSyncInbound only contain one value anyway (the Boolean IsSyncAllowed), why not just add them as Booleans within MSFT_AADCrossTenantIdentitySyncPolicyPartner directly? This might fix the issue.

Borgquite avatar Mar 26 '26 14:03 Borgquite

Thanks @FabienTschanz - appreciate you sorting this so quickly!

Borgquite avatar Mar 27 '26 10:03 Borgquite