fix: Handle PnP disconnection errors gracefully in Connect-SharePoint
This commit is contained in:
parent
321d07f217
commit
5e61686d51
@ -39,11 +39,16 @@ function Connect-SharePoint {
|
||||
throw "Please enter a Site URL"
|
||||
}
|
||||
|
||||
# Disconnect any existing connection first
|
||||
Disconnect-PnPOnline -ErrorAction SilentlyContinue
|
||||
# Try to disconnect, but ignore any errors
|
||||
try {
|
||||
Disconnect-PnPOnline
|
||||
}
|
||||
catch {
|
||||
# Ignore disconnection errors
|
||||
}
|
||||
|
||||
# Use modern authentication with device code flow
|
||||
Connect-PnPOnline -Url $siteUrl -Interactive -ForceAuthentication `
|
||||
Connect-PnPOnline -Url $siteUrl -Interactive `
|
||||
-ErrorAction Stop `
|
||||
-WarningAction SilentlyContinue
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user