From 5e61686d51293ea173827209b6de478a3eb021c2 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Wed, 19 Feb 2025 15:14:14 -0800 Subject: [PATCH] fix: Handle PnP disconnection errors gracefully in Connect-SharePoint --- SharePointFunctions.ps1 | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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