Skip to content

[BUG] Unsuccessful operation on a SPO site changes PnP context URL to admin site #5198

@dt-flo

Description

@dt-flo

Reporting an Issue or Missing Feature

I am trying to reuse an existing SPO session to access multiple sites. When I change the URL in the connection object, I can access a different SPO site without having to re-authenticate. However, when one command fails, PnP PowerShell automatically changes the PnP Context URL back to the URL of the admin center.

Expected behavior

The URL in the PnP connection object should not change back to the admin SPO site if command exeuction fails.

Actual behavior

As soon as one command execution fails, the connection object changes the destination URL back to the SharePoint admin site. Further commands are no longer executed on the target SPO site but instead on the admin site.

Steps to reproduce behavior

PS >$conobj = Connect-PnPOnline -Url 'https://contoso-admin.sharepoint.com' -ClientId 'b929ffe0-5843-4582-96f6-a3cce2fac393' -ReturnConnection:$true
PS >get-pnpcontext -Connection $conobj | Select-Object -Property "Url"

Url
---
https://contoso-admin.sharepoint.com/

PS >$temp_context = [Microsoft.SharePoint.Client.ClientContextExtensions]::Clone($(get-pnpcontext -Connection $conobj),"https://contoso.sharepoint.com/sites/ThisSiteDoesNotExist")
PS >set-pnpcontext -Context $temp_context -connection $conobj
PS >get-pnpcontext -Connection $conobj | Select-Object -Property "Url"

Url
---
https://contoso.sharepoint.com/sites/ThisSiteDoesNotExist

PS >get-pnpsite -connection $conobj
Get-PnPSite: Unexpected response from the server. The content type of the response is "text/plain; charset=utf-8". The status code is "NotFound".
PS >get-pnpcontext -Connection $conobj | Select-Object -Property "Url"

Url
---
https://contoso-admin.sharepoint.com/

PS >

What is the version of the Cmdlet module you are running?

3.1.0

Which operating system/environment are you running PnP PowerShell on?

  • Windows
  • Linux
  • MacOS
  • Azure Cloud Shell
  • Azure Functions
  • Other : please specify

If this bug report is in the wrong repository, please comment and I will close it here and re-create it in the correct repo.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions