Microsoft365DSC icon indicating copy to clipboard operation
Microsoft365DSC copied to clipboard

Export for SPOApp Fails

Open pluethi1 opened this issue 1 year ago • 4 comments

Description of the issue

When trying to export SPOApp with service principal and certificate thumbprint, it fails with the following output:

Exporting Microsoft 365 configuration for Components: SPOApp

Authentication methods specified:
- Service Principal with Certificate Thumbprint

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

    |---[1/2] pnp-modern-search-parts-v4.sppkg✅
    |---[2/2] ❌
Error Log created at {file://C:/Windows/system32/34904-M365DSC-ErrorLog.log}
⌛ Export took {3 seconds} for {1 instances}
Join-Path : Cannot find path 'C:\Users\<MY_USER>\AppData\Local\Temp\pnp-modern-search-parts-v4.sppkg' because it does not
exist.
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1:858 char:37
+ ...             $filePath = Join-Path $env:Temp $fileToCopy.Name -Resolve
+                             ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : ObjectNotFound: (C:\Users\<MY_USER>\A...-parts-v4.sppkg:String) [Join-Path], ItemNotFoundExce
   ption
    + FullyQualifiedErrorId : PathNotFound,Microsoft.PowerShell.Commands.JoinPathCommand

Partial Export file was saved at: C:\Users\<MY_USER>\AppData\Local\Temp\1fd37a79-2825-4650-9729-b55c3ad5c2cb.partial.ps1
Copy-Item : Cannot bind argument to parameter 'Path' because it is null.
At C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1:860 char:41
+                         Copy-Item -Path $filePath -Destination $destP ...
+                                         ~~~~~~~~~
    + CategoryInfo          : InvalidData: (:) [Copy-Item], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.CopyItemCom
   mand

Could it be that something is configured in a wierd way on our SharePoint? Or is this an issue with the PS module?

Microsoft 365 DSC Version

1.25.212.2

Which workloads are affected

SharePoint Online

The DSC configuration

n.A.

Verbose logs showing the problem

[2025/02/20 12:07:56]
{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)
"Error during Export:"
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1: line 413
at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1: line 689
at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 1491
at <ScriptBlock>, <No file>: line 1
TenantId: <MY_COMPANY>.onmicrosoft.com

Environment Information + PowerShell Version

OsName               : Microsoft Windows 10 Pro
OsOperatingSystemSKU : 48
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 19041.1.amd64fre.vb_release.191206-1406
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

Name                           Value
----                           -----
PSVersion                      5.1.19041.5486
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.5486
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

pluethi1 avatar Feb 20 '25 11:02 pluethi1

+1 I'm facing the same issue.

Same version of DSC: 1.25.212.2

Tested in PowerShell 5.1

PSVersion 5.1.20348.2652 PSEdition Desktop PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...} BuildVersion 10.0.20348.2652 CLRVersion 4.0.30319.42000 WSManStackVersion 3.0 PSRemotingProtocolVersion 2.3 SerializationVersion 1.1.0.1

- App registration

Authentication methods specified:

  • Service Principal with Certificate Thumbprint

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

|---[1/4] pnp-modern-search-parts-v4.sppkg✅
|---[2/4] pnp-react-search-refiners.sppkg✅
|---[3/4] customlearning.sppkg✅
|---[4/4] ❌

LOGFILE:

[2025/02/21 10:25:25] {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) "Error during Export:" at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1: line 413 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1: line 689 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 1512

- Managed Identity

Connecting to {PnP}...✅ [1/1] Extracting [SPOApp] using {ManagedIdentity}...Error Log created at {file://C:/Users/admin.vancaef/Desktop/VANCAEF-debug/Scripts/Baseline/9552-M365DSC-ErrorLog.log} ✅ ⌛ Export took {214 seconds} for {0 instances} Error Log created at {file://C:/Users/admin/Desktop/debug/Scripts/Baseline/9552-M365DSC-ErrorLog.log} PS C:\Users\admin.vancaef\Desktop\VANCAEF-debug\Scripts\Baseline>

LOGFILE: [2025/02/21 10:32:05] {WriteError} System.ArgumentException: The specified list was not found at PnP.PowerShell.Commands.Files.FindFile.ExecuteCmdlet() at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() "The specified list was not found" at Get-AllSPOPackages, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 2884 at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1: line 391

[2025/02/21 10:32:06] {WriteError} System.ArgumentException: The specified list was not found at PnP.PowerShell.Commands.Files.FindFile.ExecuteCmdlet() at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() "The specified list was not found" at Get-AllSPOPackages, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 2884 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1: line 849 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 1512

Tested in PowerShell 7:

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

- App registration Authentication methods specified:

  • Service Principal with Certificate Thumbprint

Connecting to {PnP}...✅ [1/1] Extracting [SPOApp] using {CertificateThumbprint}...Error Log created at {file://C:/Users/admin.vancaef/Desktop/VANCAEF-debug/Scripts/Baseline/10804-M365DSC-ErrorLog.log} ✅ ⌛ Export took {115 seconds} for {0 instances}

LOGFILE: [2025/02/21 10:24:38] {WriteError} System.ArgumentException: The specified list was not found at PnP.PowerShell.Commands.Files.FindFile.ExecuteCmdlet() in c:\build\src\Commands\Files\FindFile.cs:line 31 at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 51 "The specified list was not found" at Get-AllSPOPackages, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 2884 at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\DSCResources\MSFT_SPOApp\MSFT_SPOApp.psm1: line 391 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1: line 689 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 1512

[2025/02/21 10:24:39] {WriteError} System.ArgumentException: The specified list was not found at PnP.PowerShell.Commands.Files.FindFile.ExecuteCmdlet() in c:\build\src\Commands\Files\FindFile.cs:line 31 at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 51 "The specified list was not found" at Get-AllSPOPackages, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 2884 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCReverse.psm1: line 849 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.212.2\Modules\M365DSCUtil.psm1: line 1512

- Managed Identity Same as with the app registration

So the testing in 4 cases is 3 times the same result, only PS5.1 with app registration, there is a different result

fvancaelenbergnbb avatar Feb 21 '25 10:02 fvancaelenbergnbb

I also have this issue - i have an exported Capture file but parsing that is nigh on impossible

{InvalidOperation} System.Management.Automation.RuntimeException: Method invocation failed because [PnP] does not contain a method named 'MemberwiseClone'. 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) 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(Action1 clause, Object dollarUnderbar, Object inputToProcess) at System.Management.Automation.CommandProcessorBase.Complete() "Error retrieving data:" at Clone, C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.37\ConnectionProfile.ps1: line 131 at Get-MSCloudLoginConnectionProfile, C:\Program Files\WindowsPowerShell\Modules\MSCloudLoginAssistant\1.1.37\MSCloudLoginAssistant.psm1: line 402 at Get-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\DSCResources\MSFT_SPOTenantSettings\MSFT_SPOTenantSettings.psm1: line 215 at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\DSCResources\MSFT_SPOTenantSettings\MSFT_SPOTenantSettings.psm1: line 852 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\Modules\M365DSCReverse.psm1: line 689 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\Modules\M365DSCUtil.psm1: line 1491 at , : line 1

and

{WriteError} System.ArgumentException: The specified list was not found at PnP.PowerShell.Commands.Files.FindFile.ExecuteCmdlet() in c:\build\src\Commands\Files\FindFile.cs:line 31 at PnP.PowerShell.Commands.Base.PnPConnectedCmdlet.ProcessRecord() in c:\build\src\Commands\Base\PnPConnectedCmdlet.cs:line 51 "The specified list was not found" at Get-AllSPOPackages, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\Modules\M365DSCUtil.psm1: line 2884 at Start-M365DSCConfigurationExtract, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\Modules\M365DSCReverse.psm1: line 849 at Export-M365DSCConfiguration, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\Modules\M365DSCUtil.psm1: line 1491 at , : line 1

Royhutton avatar Mar 06 '25 09:03 Royhutton

@Royhutton You are using PowerShell 7.5.0 right? Please use Windows PowerShell 5.1 for now, as there is a bug in PowerShell 7.5. that leads to the exception you're experiencing.

FabienTschanz avatar Mar 07 '25 22:03 FabienTschanz

We have also this Issue over here with PS 5.1. After a bit of debugging the Issue seems to come from Get-AllSPOPackages in M365DSCUtil.psm1. https://github.com/microsoft/Microsoft365DSC/blob/Dev/Modules/Microsoft365DSC/Modules/M365DSCUtil.psm1#L2564

When I add a $null check like this all starts to work as expected.

               foreach ($file in $allFiles)
                {
                    If($null -ne  $file) {
                        $filesToDownload += @{Name = $file.Name; Site = $tenantAppCatalogUrl; Title = $file.Title }
                    }
                }

TimSaueressig avatar May 09 '25 08:05 TimSaueressig