microsoft / Microsoft365DSC

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

Fail to backup after exception on SPOApp component #4557

Open gitbpotalan opened 5 months ago

gitbpotalan commented 5 months ago

Description of the issue

Workload SPO backup seems to progress versus SPO component fail to backup and shutdown the backup process when exception occurs I just want the process to keep going even if it encounters an error

image

I tried Export-M365DSCConfiguration -ErrorAction Continue and even -ErrorActionPreference Continue at the beginning of the script but nothing works

Microsoft 365 DSC Version

1.24.403.1

Which workloads are affected

SharePoint Online

The DSC configuration

$Components += @("SPOAccessControlSettings", "SPOApp", "SPOBrowserIdleSignout", "SPOHomeSite", "SPOHubSite", "SPOOrgAssetsLibrary", "SPOPropertyBag", "SPOSearchManagedProperty", "SPOSearchResultSource", "SPOSharingSettings", "SPOSite", "SPOSiteAuditSettings", "SPOSiteDesign", "SPOSiteDesignRights", "SPOSiteGroup", "SPOSiteScript", "SPOStorageEntity", "SPOTenantCdnEnabled", "SPOTenantCdnPolicy", "SPOTenantSettings", "SPOTheme", "SPOUserProfileProperty")

Foreach($Component in $(($AllComponents | ?{$_.Service -eq $Service}).Components)) {
Export-M365DSCConfiguration -CertificateThumbprint $cert.Thumbprint -TenantId $TenantId -ApplicationId $ApplicationId -Path "$DSCExport\$Service`_$FormattedDateForDirectoryFormat" -FileName "$Component.ps1" -Components @("$Component")
}

Verbose logs showing the problem

Connecting to {PnP}...✅
[1/1] Extracting [SPOApp] using {CertificateThumbprint}...

    |---[1/2] ses-tree-view.sppkg✅
    |---[2/2] ❌
 Error Log created at {file://C:/scripts/DSC/20120-M365DSC-ErrorLog.log}
⌛ Export took {2 seconds}
Join-Path : Cannot find path 'C:\Users\BPOULA~1.EXT\AppData\Local\Temp\ses-tree-view.sppkg' because it does not exist.
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.403.1\Modules\M365DSCReverse.psm1:816 char:37
+ ...             $filePath = Join-Path $env:Temp $fileToCopy.Name -Resolve
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\BPOULA...tree-view.sppkg:String) [Join-Path], ItemNotFoundException
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

Partial Export file was saved at: C:\Users\BPOULA~1.EXT\AppData\Local\Temp\52dc648f-0126-497f-b722-babbb1ee11d5.partial.ps1
Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.403.1\Modules\M365DSCReverse.psm1:818 char:41
+                         Copy-Item -Path $filePath -Destination $destP ...
+                                         ~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCommand

Environment Information + PowerShell Version

OsName               : Microsoft Windows Server 2022 Datacenter
OsOperatingSystemSKU : DatacenterServerEdition
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 20348.1.amd64fre.fe_release.210507-1500
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PSVersion                      5.1.20348.2227
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.20348.2227
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
cpc-alruba commented 5 months ago

Having the exact same issue with DSC version 1.24.403.1. In my case, I'm working to extract entire SPO workload with Default mode. The issue started a couple of weeks ago, the last successful export we had for SPO workload was April 1st then we start noticing this issue.

I updated all dependencies and removed the old ones too to no avail. Surprisingly, its only failing when extracting SPO workload and still works fine with other workloads such as EXO and Teams.

Main issues we noticed before the script fail prematurely are:

  1. Failure to extract some of the SPOApp component
  2. Failure to extract some of the SPOHubSite component with error (Get-MgGroup .... objects are not present (Not found)
  3. a Join-Path error after extract complete due to missing an app path then script ends prematurely and fail to export the results

Error logs from today's export attempt:

[2024/04/16 09:12:38] {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.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) "Error during Export:" at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.403.1\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1: line 395 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.403.1\Modules\M365DSCReverse.psm1: line 649 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.24.403.1\Modules\M365DSCUtil.psm1: line 1349 at , C:\Scripts\M365DSCAutomation-SharePoint.ps1: line 52 at , : line 1 TenantId: *** ` image

image

cpc-alruba commented 4 months ago

@andikrueger is this something you can help with?

cpc-alruba commented 4 months ago

Workaround Solution: I had to disable the error handling CmdLets under the "M365DSCReverse.psm1" file to allow the script to continue to run without interruption!

image

Still have to deal with why I'm getting access denied when exporting the "Get-MgAdminSharepointSetting" despite having the API permission "Organization.Read.All" in my service principal!

image image