diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 2092225..81c79a4 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -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