microsoft / Microsoft365DSC

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

Export-M365DSCConfiguration: Getting `You cannot call a method on a numm-valued expression` and empty report with PowerShell 7. #4789

Closed CollinB42 closed 2 months ago

CollinB42 commented 3 months ago

Description of the issue

I've been having some issues getting DSC to run, the amount of these errors it gets seems to cancel the script/module past a certain point. I've tried running M365DSC with the default configuration, and with various configurations from the web UI. This is all with PowerShell 7, as I haven't gotten the module to work correctly with PowerShell 5.

I've gone through and verified Graph API permissions for PowerShell and don't think this is the cause. The tool is able to grab some information but not all, and some cmdlets do error out due to a lack of licensing for the feature it's attempting to pull information from.

{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 System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   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:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 3449
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\DSCResources\MSFT_AADAuthenticationMethodPolicyVoice\MSFT_AADAuthenticationMethodPolicyVoice.psm1: line 567
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCReverse.psm1: line 682
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 1397
at <ScriptBlock>, <No file>: line 1```

### Microsoft 365 DSC Version

V1.24.619.1

### Which workloads are affected

Azure Active Directory (Entra ID), Exchange Online

### The DSC configuration

```powershell
Export-M365DSCConfiguration -Path C:\(placeholder)\Microsoft365DSCExports -Verbose

Verbose logs showing the problem

{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 System.Management.Automation.Interpreter.ActionCallInstruction`2.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.Interpreter.Run(InterpretedFrame frame)
   at System.Management.Automation.Interpreter.LightLambda.RunVoid1[T0](T0 arg0)
   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:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 3449
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\DSCResources\MSFT_AADAuthenticationMethodPolicyX509\MSFT_AADAuthenticationMethodPolicyX509.psm1: line 672
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCReverse.psm1: line 682
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 1397
at <ScriptBlock>, <No file>: line 1

Error during Export:

{ The term 'Get-DataClassification' is not recognized as a name of a cmdlet, function, script file, or executable program.
 \ Check the spelling of the name, or if a path was included, verify that the path is correct and try again. } \ at Export-TargetResource, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\DSCResources\MSFT_EXODataClassification\MSFT_EXODataClassification.psm1: line 445
 \ at Start-M365DSCConfigurationExtract, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCReverse.psm1: line 682
 \ at Export-M365DSCConfiguration, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 1397
 \ at <ScriptBlock>, <No file>: line 1

Error during Export:

{ You cannot call a method on a null-valued expression. } \ at Get-M365DSCExportContentForResource, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 3449
 \ at Export-TargetResource, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\DSCResources\MSFT_EXOCASMailboxSettings\MSFT_EXOCASMailboxSettings.psm1: line 816
 \ at Start-M365DSCConfigurationExtract, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCReverse.psm1: line 682
 \ at Export-M365DSCConfiguration, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 1397
 \ at <ScriptBlock>, <No file>: line 1

Error during Export:

{ You cannot call a method on a null-valued expression. } \ at Get-M365DSCExportContentForResource, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 3449
 \ at Export-TargetResource, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\DSCResources\MSFT_EXOCASMailboxPlan\MSFT_EXOCASMailboxPlan.psm1: line 459
 \ at Start-M365DSCConfigurationExtract, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCReverse.psm1: line 682
 \ at Export-M365DSCConfiguration, C:\Users\(placeholder)\Documents\PowerShell\Modules\Microsoft365DSC\1.24.619.1\Modules\M365DSCUtil.psm1: line 1397
 \ at <ScriptBlock>, <No file>: line 1

Environment Information + PowerShell Version

OsName               : Microsoft Windows Server 2016 Standard
OsOperatingSystemSKU : StandardServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 1607
WindowsBuildLabEx    : 14393.7070.amd64fre.rs1_release.240606-1636
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Key   : PSVersion
Value : 7.4.3
Name  : PSVersion

Key   : PSEdition
Value : Core
Name  : PSEdition

Key   : GitCommitId
Value : 7.4.3
Name  : GitCommitId

Key   : OS
Value : Microsoft Windows 10.0.14393
Name  : OS

Key   : Platform
Value : Win32NT
Name  : Platform

Key   : PSCompatibleVersions
Value : {1.0, 2.0, 3.0, 4.0…}
Name  : PSCompatibleVersions

Key   : PSRemotingProtocolVersion
Value : 2.3
Name  : PSRemotingProtocolVersion

Key   : SerializationVersion
Value : 1.1.0.1
Name  : SerializationVersion

Key   : WSManStackVersion
Value : 3.0
Name  : WSManStackVersion
FabienTschanz commented 3 months ago

PowerShell 7 is not yet correctly supported in Microsoft365DSC. Please uninstall all modules from inside the PowerShell 7 window, then do the same from PowerShell 5, and install the module again in PowerShell 5. The modules must be installed system wide and not in the current user scope.

FabienTschanz commented 2 months ago

@CollinB42 Did you try the steps I suggested? Can we close this issue?

CollinB42 commented 2 months ago

@CollinB42 Did you try the steps I suggested? Can we close this issue?

Hey @FabienTschanz, I was able to get this working with a clean install in PowerShell 5!

FabienTschanz commented 2 months ago

Awesome, glad to hear you got it working. There are a couple of improvements that I made over in the https://github.com/microsoft/Microsoft365DSC/pull/4916 Pull Request. Can you or @andikrueger close this issue here therefore?

CollinB42 commented 2 months ago

Sure can!