Skip to content

The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect. #3499

@faisaleem-na

Description

@faisaleem-na

Discussed in #2465

Originally posted by ItsTerryDuckett October 14, 2022
I have an Azure Runbook with a system managed identity. I'm using the following code as a simple test:

$conn = Connect-PnPOnline -Url "https://tenant.sharepoint.com/sites/sitename" -ManagedIdentity -ReturnConnection
$list = Get-PnPList -Identity "listid" -Connection $conn

The "Connect-PnPOnline -ManagedIdentity" works fine and connects. However, the next line, "$list = Get-PnPList -Identity "listid" -Connection $conn" returns the following error:
"The current connection holds no SharePoint context. Please use one of the Connect-PnPOnline commands which uses the -Url argument to connect."

If I switch the runbook back to using a "runas" account, it works fine.
If I try and use "Connect-PnPOnline -ManagedIdentity -Url $url" the above error occurs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions