Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export-M365Configuration: The current connection holds no SharePoint context #5831

Open
gavdgavd opened this issue Feb 23, 2025 · 0 comments

Comments

@gavdgavd
Copy link

Description of the issue

I have installed the latest version of Microsoft365DSC (version 1.25.219.2, February 22, 2025). Additionally, I have an Entra ID App Registration with the necessary SharePoint and Graph claims, made using the "Register-PnPAzureADApp -Interactive" cmdlet. The App Registration is added to the Certificate Store of the Windows computer. When I run the command:

Export-M365DSCConfiguration -ApplicationId "xxxx-xxxx-xxxx-xxxx-xxxx" -TenantId "mydomain.onmicrosoft.com" -CertificateThumbprint "xxxxx" -Components @("SPOSite") -ConfigurationName "MyConfig" -Path "C:\Temporary\DSC" -FileName "MyConfig.ps1" -GenerateInfo $true

I get the error "The current connection holds no SharePoint context".
Note: I also tried using a manually created App Registration with all claims. Additionally, I ran the script from two different computers, both running Windows 11 with admin rights and the latest Microsoft365DSC module.
Note: I also tried using different SharePoint components, such as "SPOAccessControlSettings", "SPOBrowserIdleSignout", "SPOHomeSite", "SPOTenantCdnPolicy", and "SPOTenantSettings", which are related to the admin site collection of SharePoint, not to a specific site collection, with the same result.
Note: Using PowerShell version 5, NOT 7.x.

Microsoft 365 DSC Version

1.25.219.2

Which workloads are affected

SharePoint Online

The DSC configuration

Verbose logs showing the problem

PS C:\Users\xxxx> Export-M365DSCConfiguration -ApplicationId "xxxx" -TenantId "mytenant.onmicrosoft.com" -CertificateThumbprint "xxxx" -Components @("SPOSite") -ConfigurationName "MyConfig" -Path "C:\Temporary\DSC" -FileName "MyConfig.ps1" -GenerateInfo $true -Verbose
VERBOSE: No existing connections to Microsoft Graph
Exporting Microsoft 365 configuration for Components: SPOSite

Authentication methods specified:
- Service Principal with Certificate Thumbprint

VERBOSE: Removing the imported "Test-TargetResource" function.
VERBOSE: Removing the imported "Set-TargetResource" function.
VERBOSE: Removing the imported "Get-TargetResource" function.
VERBOSE: Removing the imported "Export-TargetResource" function.
VERBOSE: Loading module from path 'C:\Program
Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\DSCResources\MSFT_SPOSite\MSFT_SPOSite.psm1'.
VERBOSE: Importing function 'Export-TargetResource'.
VERBOSE: Importing function 'Get-TargetResource'.
VERBOSE: Importing function 'Set-TargetResource'.
VERBOSE: Importing function 'Test-TargetResource'.
Connecting to {PnP}...✅
[1/1] Extracting [SPOSite] using {CertificateThumbprint}...VERBOSE: Attempting connection to {PnP} with:
VERBOSE:
Name                           Value

----                           -----

CertificateThumbprint          xxxx

TenantId                       mytenant.onmicrosoft.com

ApplicationId                  xxxx



VERBOSE: ApplicationId, TenantId, CertificateThumbprint were specified. Connecting via Service Principal
VERBOSE: Calling into Connect-M365Tenant
VERBOSE: Connection initiated.
VERBOSE: Dependencies were already successfully validated.
❌
Error Log created at {file://C:/Users/xxxx/6132-M365DSC-ErrorLog.log}
⌛ Export took {1 seconds} for {0 instances}

-----------------------------------------------------------------------------------

ErrorLog.log:

[2025/02/23 12:05:52]
{NotSpecified}
System.InvalidOperationException: The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect.
   at PnP.PowerShell.Commands.PnPSharePointCmdlet.BeginProcessing()
   at PnP.PowerShell.Commands.Base.PnPAdminCmdlet.BeginProcessing()
   at System.Management.Automation.Cmdlet.DoBeginProcessing()
   at System.Management.Automation.CommandProcessorBase.DoBegin()
"Error during Export:"
at Export-TargetResource, C:\Program Files\WindowsPowerShell\Modules\Microsoft365DSC\1.25.219.2\DSCResources\MSFT_SPOSite\MSFT_SPOSite.psm1: line 930
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 1512
at <ScriptBlock>, <No file>: line 1
TenantId: mydomain.onmicrosoft.com

Environment Information + PowerShell Version

OsName               : Microsoft Windows 11 Pro N
OsOperatingSystemSKU : 49
OsArchitecture       : 64-bit
WindowsVersion       : 2009
WindowsBuildLabEx    : 22000.1.amd64fre.co_release.210604-1628
OsLanguage           : en-US
OsMuiLanguages       : {en-US}

PowerShell version: 
Major  Minor  Build  Revision
-----  -----  -----  --------
5      1      22000  2538
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant