powershell
powershell copied to clipboard
[BUG] Disconnect-PnPOnline Documentation doesn't match Connect-PnPOnline operation (Ambiguous docco)
Expected behavior
As documented for Disconnect-PnPOnline docco; "If instead you simply want to connect to another site collection within the same tenant using the same credentials you used previously, do not use this cmdlet but instead use Connect-PnPOnline -Url https://tenant.sharepoint.com/sites/othersite instead without disconnecting. It will try to reuse the existing authentication method and cached credentials."
Extra Question (for bonus points)
Is there a method of accessing and re-using the Authentication Details with an -interactive MFA connection? I want to:
- Connect to site A -interactively using the Web/MFA Dialog
- Connect to site B using the same credentials but not having to re-enter them via a second Web/MFA Dialog
Actual behavior
IF you're using the Connect-PnPOnline -Interactive method, you're prompted for credentials again on attempting to connect to second site.
Steps to reproduce behavior
# First connection Displays Web Auth dialog box for MFA Authentication as expected
$ProjectSiteConn = Connect-PnPOnline -URL $ProjectsURL -interactive -ReturnConnection
# Second connection Displays Windows Authentication Dialog - not as described in Disonnect-PnPOnline docco above
$SharedSiteConn = Connect-PnPOnline -URL $SharedURL -ReturnConnection
Including -interactive on the second connection string prompts for Web/MFA Authentication again. (inclusion or omission of -ReturnConnection is irrelevant).
What is the version of the Cmdlet module you are running?
1.11.0
Which operating system/environment are you running PnP PowerShell on?
- [x] Windows
- [ ] Linux
- [ ] MacOS
- [ ] Azure Cloud Shell
- [ ] Azure Functions
- [ ] Other : please specify
Have you tried connecting to a site, then using Get-PnPAccessToken to fetch the current access token? You could then use that access token to connect again:
Connect-PnPOnline -Url https://contoso.sharepoint.com -AccessToken $token
These tokens do tend to expire after an hour, so it may or may not be suitable for your use case.
Have you tried connecting to a site, then using Get-PnPAccessToken to fetch the current access token? You could then use that access token to connect again
...no I haven't. I wasn't aware of that Cmdlet. ..tweaks code.. 😲 OMG it worked. Thankyou @CallumCrowley !