microsoft / Microsoft365DSC

Manages, configures, extracts and monitors Microsoft 365 tenant configurations
https://aka.ms/M365DSC
MIT License
1.64k stars 505 forks source link

New-M365DSCReportFromConfiguration: Cannot index into a null array. $resource.CommandElements[2].KeyValuePairs #5135

Closed dominicbuehrer closed 1 month ago

dominicbuehrer commented 2 months ago

Description of the issue

I export the EXO configuration with defined components and certificate authentication using an app registration.

Export-M365DSCConfiguration -Components $CustomComponents -Path ("$LogPath\$Workload") -FileName ("$($Workload)_$($Mode)_ConfigurationData.ps1") -ConfigurationName ("$($Workload)_$($Mode)_ConfigurationData.psd1") -ApplicationId $ApplicationId -TenantId $TenantId ` -CertificateThumbprint $CertificateThumbprint

This works absolutly fine. But when I try to create a new html report from the configuration it fails. The html report was succesfully created for AAD and SPO

Components: EXOAcceptedDomain EXOActiveSyncDeviceAccessRule EXOAddressBookPolicy EXOAddressList EXOAntiPhishPolicy EXOAntiPhishRule EXOApplicationAccessPolicy EXOAtpPolicyForO365 EXOAuthenticationPolicy EXOAuthenticationPolicyAssignment EXOAvailabilityAddressSpace EXOAvailabilityConfig EXOCASMailboxPlan EXOClientAccessRule EXODataClassification EXODataEncryptionPolicy EXODkimSigningConfig EXOEmailAddressPolicy EXOGlobalAddressList EXOHostedConnectionFilterPolicy EXOHostedContentFilterPolicy EXOHostedContentFilterRule EXOHostedOutboundSpamFilterPolicy EXOHostedOutboundSpamFilterRule EXOInboundConnector EXOIntraOrganizationConnector EXOIRMConfiguration EXOJournalRule EXOMailboxPlan EXOMailTips EXOMalwareFilterPolicy EXOMalwareFilterRule EXOManagementRole EXOManagementRoleAssignment EXOMessageClassification EXOMobileDeviceMailboxPolicy EXOOfflineAddressBook EXOOMEConfiguration EXOOnPremisesOrganization EXOOrganizationConfig EXOOrganizationRelationship EXOOutboundConnector EXOOwaMailboxPolicy EXOPartnerApplication EXOPerimeterConfiguration EXOPolicyTipConfig EXOQuarantinePolicy EXORemoteDomain EXOReportSubmissionPolicy EXOReportSubmissionRule EXOResourceConfiguration EXORoleAssignmentPolicy EXORoleGroup EXOSafeAttachmentPolicy EXOSafeAttachmentRule EXOSafeLinksPolicy EXOSafeLinksRule EXOSharingPolicy EXOTransportConfig EXOTransportRule EXORecipientPermission EXOManagementRoleEntry

Microsoft 365 DSC Version

V1.24.904.1

Which workloads are affected

Exchange Online

The DSC configuration

New-M365DSCReportFromConfiguration -type html -configurationPath D:\M365\Microsoft365DSC\EXO\EXO_Custom_ConfigurationData.ps1 -OutputPath D:\M365\Microsoft365DSC\EXO\EXO_Custom_M365TenantConfig.html

Verbose logs showing the problem

Cannot index into a null array.
At C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.8\Modules\DSCParser.psm1:534 char:9
+         $resourceType         = $resource.CommandElements[0].Value
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.8\Modules\DSCParser.psm1:535 char:9
+         $resourceInstanceName = $resource.CommandElements[1].Value
+         ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Cannot index into a null array.
At C:\Program Files\WindowsPowerShell\Modules\DSCParser\2.0.0.8\Modules\DSCParser.psm1:548 char:35
+ ... foreach ($keyValuePair in $resource.CommandElements[2].KeyValuePairs)
+                               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (:) [], RuntimeException
    + FullyQualifiedErrorId : NullArray

Environment Information + PowerShell Version

Name                           Value                                                                                                                                                                                                             
----                           -----                                                                                                                                                                                                             
PSVersion                      5.1.14393.7330                                                                                                                                                                                                    
PSEdition                      Desktop                                                                                                                                                                                                           
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}                                                                                                                                                                                           
BuildVersion                   10.0.14393.7330                                                                                                                                                                                                   
CLRVersion                     4.0.30319.42000                                                                                                                                                                                                   
WSManStackVersion              3.0                                                                                                                                                                                                               
PSRemotingProtocolVersion      2.3                                                                                                                                                                                                               
SerializationVersion           1.1.0.1
FabienTschanz commented 2 months ago

@dominicbuehrer Please update to Microsoft365DSC 1.24.1002.1 using Update-M365DSCModule. The problem should then be clearer. It's either running winrm quickconfig -force or running the command in an administrative Windows PowerShell session.

dominicbuehrer commented 2 months ago

Hi @FabienTschanz

Thanks for your response. I've updated the module and it dependencies and now the M365DSCReportFromConfiguration for AAD does not work either.

i'm running the command in an administrative PowerShell session. Also winrm is running.

C:\Windows\system32 () 2024-10-03 17:02:24.373 (+02:00)> winrm quickconfig -force WinRM service is already running on this machine. WinRM is already set up for remote management on this computer.

FabienTschanz commented 2 months ago

I guess you restarted the PowerShell session, right? That's necessary, otherwise some things will still remain in memory for the time being. Can you please share a minimal version of your EXO_Custom_ConfigurationData.ps1 file? Then we can have a look at it.

For the time being, I have something for you to test. Can you please run the following scripts? They will check if the DSCParser works correctly in your environment. Test-ConvertToDSCObjectV5.ps1.txt Test-ConvertToDSCObjectV4.ps1.txt

dominicbuehrer commented 2 months ago

@FabienTschanz

Looks like this is the issue from the config: image

Any chance this can be ignored or must the disclaimer text be changed?

FabienTschanz commented 2 months ago

Puh that's nasty. Can you please remove the second escape quote where there are doubles?

``"100%``" --> `"100%`"

Also, can you please copy the text from the transport rule how it's shown in the Exchange environment and upload it by text file here? Then I can try and have a look at optimizing the output.

dominicbuehrer commented 2 months ago

With your suggested modification it works fine.

Here the config from EXO and the one from the M365 DSC report.

Microsoft365 DSC.txt

FabienTschanz commented 2 months ago

Yeah, you have to update the disclaimer text to not include any of the escape quotes (in Exchange Online) to have a correct export. In PowerShell, you do have to specify them since there are additional " double quotes in the HTML text which otherwise would break the parsing. Does that make any sense?

ricmestre commented 2 months ago

This resource already caused issues in the past, I talked about it with @andikrueger and the idea was that the fields need to be properly escaped otherwise you get this problem.

FabienTschanz commented 2 months ago

So you mean even more escapes to the escapes if escapes are present? That's gonna be a real nightmare...

ricmestre commented 2 months ago

Here's the issue I was talking about where we discussed this #4377

FabienTschanz commented 2 months ago

Okay I see, so escaping the escape quotes is still missing. I'll take a look at that.

FabienTschanz commented 2 months ago

PR open https://github.com/microsoft/ReverseDSC/pull/37.