microsoft/Microsoft365DSC

Export-M365DSCConfiguration - System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.

pelicansurf opened this issue · 3 comments

Description of the issue

Export-M365DSCConfiguration -Components @("SPOAccessControlSettings", "SPOApp", "SPOBrowserIdleSignout", "SPOHomeSite", "SPOHubSite", "SPOOrgAssetsLibrary", "SPOPropertyBag", "SPOSearchManagedProperty", "SPOSearchResultSource", "SPOSharingSettings", "SPOSite", "SPOSiteAuditSettings", "SPOSiteDesign", "SPOSiteDesignRights", "SPOSiteGroup", "SPOSiteScript", "SPOStorageEntity", "SPOTenantCdnEnabled", "SPOTenantCdnPolicy", "SPOTenantSettings", "SPOTheme", "SPOUserProfileProperty") -ApplicationId $appid -CertificateThumbprint $ctp -tenantid $tid -Path 'D:\M365Export' -FileName 'M365.ps1' -verbose -debug

I keep getting System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression. for almost everything I run. Some things will work, like enterprise apps, but then once it gets past those it starts to bomb out again. It successfully exported users once, but after running it again, it runs enterprise apps, but not users, etc.

Permissions

Graph Permissions attached.

Any help would be appreciated.

Microsoft 365 DSC Version

1.24.529.1

Which workloads are affected

Azure Active Directory (Entra ID), Exchange Online, Intune, Security & Compliance Center, SharePoint Online, Teams

The DSC configuration

No response

Verbose logs showing the problem

SPO Example:

[2024/06/03 04:20:22]
{WriteError}
System.Management.Automation.RemoteException: The specified list was not found
"The specified list was not found"
at <ScriptBlock><End>, C:\...\AppData\Local\Temp\6\remoteIpMoProxy_PnPPowerShell_1.12.0_localhost_cc5384df-aa14-4357-bb5a-73599a8c1563\remoteIpMoProxy_PnPPowerShell_1.12.0_localhost_cc5384df-aa14-4357-bb5a-73599a8c1563.psm1: line 15360
at Get-AllSPOPackages, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCUtil.psm1: line 2540
at Export-TargetResource, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1: line 390
at Start-M365DSCConfigurationExtract, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCReverse.psm1: line 677
at Export-M365DSCConfiguration, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCUtil.psm1: line 1375
at <ScriptBlock>, C:\...\Documents\PowershellScripts\Export-M365DSCConfiguration.ps1: line 1
at <ScriptBlock>, <No file>: line 1

[2024/06/03 04:20:37]
{InvalidOperation}
System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at Get-M365DSCExportContentForResource(Closure, FunctionContext)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.CommandProcessorBase.Complete()
"Error during Export:"
at Get-M365DSCExportContentForResource, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCUtil.psm1: line 3439
at Export-TargetResource, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\DSCResources\MSFT_SPOBrowserIdleSignout\MSFT_SPOBrowserIdleSignout.psm1: line 388
at Start-M365DSCConfigurationExtract, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCReverse.psm1: line 677
at Export-M365DSCConfiguration, C:\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCUtil.psm1: line 1375
at <ScriptBlock>, C:\...\Documents\PowershellScripts\Export-M365DSCConfiguration.ps1: line 1
at <ScriptBlock>, <No file>: line 1

--------

AAD Example:
[2024/06/03 04:36:16]
{InvalidOperation}
System.Management.Automation.RuntimeException: You cannot call a method on a null-valued expression.
   at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception)
   at Get-M365DSCExportContentForResource(Closure, FunctionContext)
   at System.Management.Automation.PSScriptCmdlet.RunClause(Action`1 clause, Object dollarUnderbar, Object inputToProcess)
   at System.Management.Automation.CommandProcessorBase.Complete()
"Error during Export:"
at Get-M365DSCExportContentForResource, C:\Users\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCUtil.psm1: line 3439
at Export-TargetResource, C:\Users\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\DSCResources\MSFT_AADAdministrativeUnit\MSFT_AADAdministrativeUnit.psm1: line 1126
at Start-M365DSCConfigurationExtract, C:\Users\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCReverse.psm1: line 677
at Export-M365DSCConfiguration, C:\Users\...\Documents\PowerShell\Modules\Microsoft365DSC\1.24.529.1\Modules\M365DSCUtil.psm1: line 1375
at <ScriptBlock>, C:\Users\...\Documents\PowershellScripts\Export-M365DSCConfiguration.ps1: line 1
at <ScriptBlock>, <No file>: line 1

[17/40] Extracting [AADConditionalAccessPolicy] using {CertificateThumbprint}...VERBOSE: Dependencies were already successfully validated.
VERBOSE: Attempting connection to {MicrosoftGraph} with:
VERBOSE: 
Name                           Value
----                           -----
TenantId                       
CertificateThumbprint          
ApplicationId                  


VERBOSE: ApplicationId, TenantId, CertificateThumbprint were specified. Connecting via Service Principal

    |---[1/54] Exchange Online - Additional Security TestingVERBOSE: Attempting connection to {MicrosoftGraph} with:
VERBOSE: 
Name                           Value
----                           -----
Credential
DisplayName                    Exchange Online - Additional Security Testing
Id                             
AccessTokens
ManagedIdentity                False
ApplicationSecret
ApplicationId                  
TenantId                       
CertificateThumbprint          


VERBOSE: ApplicationId, TenantId, CertificateThumbprint were specified. Connecting via Service Principal
VERBOSE: Dependencies were already successfully validated.
❌
 Error Log created at {file://C:/.../11224-M365DSC-ErrorLog.log}

Environment Information + PowerShell Version

OsName               : Microsoft Windows Server 2019 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1809
WindowsBuildLabEx    : 17763.1.amd64fre.rs5_release.180914-1434
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PSVersion                      7.4.2
PSEdition                      Core
GitCommitId                    7.4.2
OS                             Microsoft Windows 10.0.17763
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

@pelicansurf Support for PowerShell 7+ is currently limited. Please try again with PowerShell 5.

I'm encountering the same issue. I hope to resolve this so we can utilize it for our enterprise customers. It worked on my sandbox machine, so I'm now investigating the differences.

So I ended up having to delete all powershell modules under my local user and I deleted the ones in program files as well to boot, any that were remotely related to Microsoft in any way. Then, on powershell 5, I installed the DSC module for all users, then I ran the Update-M365DSCDependencies module in Powershell 5 for all users. This then allowed everything to work on Powershell 5.