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"
|
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
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user