microsoft / Microsoft365DSC

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

Assert-M365DSCBlueprint "Error: Cannot index into a null array" #4941

Closed ColinHJ closed 2 weeks ago

ColinHJ commented 1 month ago

Description of the issue

I have been trying to test M365DSCBlueprint. My tests included ODSettings and AADConditionalAccessPolicy. An error occurs at line 1106 of M365DSCReport.psm1. Upon debugging, I discovered that Get-M365ResourceKey returns null to $Key at line 1104. Get-M365DSCResourceKey seems to be filtering $DSCResourceInfo for properties of $_.IsMandatory. All nested property values of $DSCResourceInfo are strings of "Microsoft.PowerShell.DesiredStateConfiguration.DSCResourcePropertyInfo". I suspect the issue arises when GET-DSCResource -Module 'Microsoft365DSC' is executed on line 739.

Microsoft 365 DSC Version

1.24.724.1

Which workloads are affected

Azure Active Directory (Entra ID), OneDrive for Business

The DSC configuration

No response

Verbose logs showing the problem

VERBOSE: Dependencies were not already validated.
VERBOSE: Populating RepositorySourceLocation property for module DSCParser.
VERBOSE: Populating RepositorySourceLocation property for module ExchangeOnlineManagement.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\ExchangeOnlineManagement\3.4.0\netCore\ExchangeOnlineManagement.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Applications.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Authentication.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.DeviceManagement.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Beta.DeviceManagement\2.20.0\Microsoft.Graph.Beta.DeviceManagement.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.Devices.CorporateManagement.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.DeviceManagement.Administration.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Beta.DeviceManagement.Administration\2.20.0\Microsoft.Graph.Beta.DeviceManagement.Administration.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.DeviceManagement.Enrollment.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Beta.DeviceManagement.Enrollment\2.20.0\Microsoft.Graph.Beta.DeviceManagement.Enrollment.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.Identity.DirectoryManagement.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.Identity.Governance.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.Identity.SignIns.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.Reports.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Beta.Reports\2.20.0\Microsoft.Graph.Beta.Reports.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.Teams.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.DeviceManagement.Administration.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.DeviceManagement.Administration\2.20.0\Microsoft.Graph.DeviceManagement.Administration.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Beta.DirectoryObjects.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Beta.DirectoryObjects\2.20.0\Microsoft.Graph.Beta.DirectoryObjects.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Groups.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Planner.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Planner\2.20.0\Microsoft.Graph.Planner.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Sites.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Sites\2.20.0\Microsoft.Graph.Sites.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Users.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.Graph.Users\2.20.0\Microsoft.Graph.Users.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.Graph.Users.Actions.
VERBOSE: Populating RepositorySourceLocation property for module Microsoft.PowerApps.Administration.PowerShell.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft.PowerApps.Administration.PowerShell\2.0.191\Microsoft.PowerApps.Administration.Powershell.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module MicrosoftTeams.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MicrosoftTeams\6.4.0\MicrosoftTeams.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module MSCloudLoginAssistant.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\ConnectionProfile.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\AzureDevOPS.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\ExchangeOnline.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\MicrosoftGraph.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\Teams.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\PnP.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\PowerPlatform.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\SecurityCompliance.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\Tasks.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\Workloads\Teams.psm1'.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.18\MSCloudLoginAssistant.psm1'.
VERBOSE: Populating RepositorySourceLocation property for module PnP.PowerShell.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\PnP.PowerShell\1.12.0\Core\PnP.PowerShell.dll'.
VERBOSE: Populating RepositorySourceLocation property for module ReverseDSC.
VERBOSE: Dependencies were all successfully validated.
VERBOSE: Requested HTTP/1.1 GET with 0-byte payload
>> TerminatingError(Invoke-WebRequest): "The 'file' scheme is not supported."
WARNING: Defined property {BlockMacSync} was not found in resource {ODSettings}
WARNING: Defined property {DisableReportProblemDialog} was not found in resource {ODSettings}
WARNING: Defined property {Ensure} was not found in resource {ODSettings}
WARNING: Defined property {IsSingleInstance} was not found in resource {ODSettings}
WARNING: Defined property {NotificationsInOneDriveForBusinessEnabled} was not found in resource {ODSettings}
WARNING: Defined property {NotifyOwnersWhenInvitationsAccepted} was not found in resource {ODSettings}
WARNING: Defined property {ODBAccessRequests} was not found in resource {ODSettings}
WARNING: Defined property {ODBMembersCanShare} was not found in resource {ODSettings}
WARNING: Defined property {OneDriveForGuestsEnabled} was not found in resource {ODSettings}
WARNING: Defined property {OneDriveStorageQuota} was not found in resource {ODSettings}
WARNING: Defined property {OrphanedPersonalSitesRetentionPeriod} was not found in resource {ODSettings}
WARNING: Defined property {TenantRestrictionEnabled} was not found in resource {ODSettings}
Selected BluePrint contains (1) components to assess.
Initiating the Export of those (1) components from the tenant...
PS>TerminatingError(Disconnect-MgGraph): "The running command stopped because the preference variable "ErrorActionPreference" or common parameter is set to Stop: No application to sign out from."
VERBOSE: No existing connections to Microsoft Graph
Exporting Microsoft 365 configuration for Components: ODSettings
VERBOSE: Exporting cmdlet 'Find-Package'.
VERBOSE: Exporting cmdlet 'Find-PackageProvider'.
VERBOSE: Exporting cmdlet 'Get-Package'.
VERBOSE: Exporting cmdlet 'Get-PackageProvider'.
VERBOSE: Exporting cmdlet 'Get-PackageSource'.
VERBOSE: Exporting cmdlet 'Import-PackageProvider'.
VERBOSE: Exporting cmdlet 'Install-Package'.
VERBOSE: Exporting cmdlet 'Install-PackageProvider'.
VERBOSE: Exporting cmdlet 'Register-PackageSource'.
VERBOSE: Exporting cmdlet 'Save-Package'.
VERBOSE: Exporting cmdlet 'Set-PackageSource'.
VERBOSE: Exporting cmdlet 'Uninstall-Package'.
VERBOSE: Exporting cmdlet 'Unregister-PackageSource'.
VERBOSE: Importing cmdlet 'Find-Package'.
VERBOSE: Importing cmdlet 'Find-PackageProvider'.
VERBOSE: Importing cmdlet 'Get-Package'.
VERBOSE: Importing cmdlet 'Get-PackageProvider'.
VERBOSE: Importing cmdlet 'Get-PackageSource'.
VERBOSE: Importing cmdlet 'Import-PackageProvider'.
VERBOSE: Importing cmdlet 'Install-Package'.
VERBOSE: Importing cmdlet 'Install-PackageProvider'.
VERBOSE: Importing cmdlet 'Register-PackageSource'.
VERBOSE: Importing cmdlet 'Save-Package'.
VERBOSE: Importing cmdlet 'Set-PackageSource'.
VERBOSE: Importing cmdlet 'Uninstall-Package'.
VERBOSE: Importing cmdlet 'Unregister-PackageSource'.

Authentication methods specified:
- Service Principal with Certificate Thumbprint

VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.724.1\DSCResources\MSFT_ODSettings\MSFT_ODSettings.psm1'.
VERBOSE: Importing function 'Export-TargetResource'.
VERBOSE: Importing function 'Get-TargetResource'.
VERBOSE: Importing function 'Set-TargetResource'.
VERBOSE: Importing function 'Test-TargetResource'.
VERBOSE: Attempting connection to {MicrosoftGraph} with:
VERBOSE: 
Name                           Value
----                           -----
ApplicationId                  xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
CertificateThumbprint          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TenantId                       xxxxxxxxxxxx.onmicrosoft.com
ApplicationSecret              
CertificatePath
VERBOSE: Initializing the Connected To Workloads List.
VERBOSE: ApplicationId, TenantId, CertificateThumbprint were specified. Connecting via Service Principal
Connecting to {PnP}...
PS>TerminatingError(Get-PnPAlert): "The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect."
✅
[1/1] Extracting [
ODSettings
] using {
CertificateThumbprint
}...
VERBOSE: Attempting connection to {PnP} with:
VERBOSE: 
Name                           Value
----                           -----
ApplicationId                  xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
CertificateThumbprint          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TenantId                       xxxxxxxxxxxx.onmicrosoft.com
VERBOSE: ApplicationId, TenantId, CertificateThumbprint were specified. Connecting via Service Principal
VERBOSE: Dependencies were already successfully validated.
VERBOSE: Attempting connection to {PnP} with:
VERBOSE: 
Name                           Value
----                           -----
CertificateThumbprint          xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
IsSingleInstance               Yes
Credential                     
ManagedIdentity                False
TenantId                       xxxxxxxxxxxx.onmicrosoft.com
AccessTokens                   
CertificatePath                
CertificatePassword            
ApplicationId                  xxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
VERBOSE: ApplicationId, TenantId, CertificateThumbprint were specified. Connecting via Service Principal
VERBOSE: Dependencies were already successfully validated.
✅
⌛ Export took {
18 seconds
} for {
1 instances
}
VERBOSE: Dependencies were already successfully validated.
PS>TerminatingError(Where-Object): "Cannot index into a null array."
Error: Cannot index into a null array.
PS>TerminatingError(Where-Object): "Cannot index into a null array."

Environment Information + PowerShell Version

Host Application: C:\Program Files\PowerShell\7-preview\pwsh.dll
Process ID: 15416
PSVersion: 7.4.4
PSEdition: Core
GitCommitId: 7.4.4
OS: Microsoft Windows 10.0.22631
Platform: Win32NT
PSCompatibleVersions: 1.0, 2.0, 3.0, 4.0, 5.0, 5.1, 6.0, 7.0
PSRemotingProtocolVersion: 2.3
SerializationVersion: 1.1.0.1
WSManStackVersion: 3.0
FabienTschanz commented 1 month ago

@ColinHJ For now, please use Windows PowerShell 5.1 instead of PowerShell 7. There are a number of issues that are still present because Microsoft365DS doesn't properly support Windows PowerShell and PowerShell 7 at the same time... I am working on it though.

ColinHJ commented 1 month ago

Thank you for the feedback, @FabienTschanz. I am experiencing better results with PowerShell 5.1.