fix: Handle PnP disconnection errors gracefully in Connect-SharePoint

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 15:14:14 -08:00
parent 321d07f217
commit 5e61686d51

View File

@ -39,11 +39,16 @@ function Connect-SharePoint {
throw "Please enter a Site URL" throw "Please enter a Site URL"
} }
# Disconnect any existing connection first # Try to disconnect, but ignore any errors
Disconnect-PnPOnline -ErrorAction SilentlyContinue try {
Disconnect-PnPOnline
}
catch {
# Ignore disconnection errors
}
# Use modern authentication with device code flow # Use modern authentication with device code flow
Connect-PnPOnline -Url $siteUrl -Interactive -ForceAuthentication ` Connect-PnPOnline -Url $siteUrl -Interactive `
-ErrorAction Stop ` -ErrorAction Stop `
-WarningAction SilentlyContinue -WarningAction SilentlyContinue