From 321d07f2171d5b6c56ede25da3f6460e999f8d38 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Wed, 19 Feb 2025 15:12:27 -0800 Subject: [PATCH] feat: Enhance SharePoint connection with error handling and verification --- SharePointFunctions.ps1 | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 01930cf..2092225 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -38,11 +38,21 @@ function Connect-SharePoint { if (-not $siteUrl) { throw "Please enter a Site URL" } + + # Disconnect any existing connection first + Disconnect-PnPOnline -ErrorAction SilentlyContinue - # Simplified interactive auth - Connect-PnPOnline -Url $siteUrl -Interactive ` + # Use modern authentication with device code flow + Connect-PnPOnline -Url $siteUrl -Interactive -ForceAuthentication ` + -ErrorAction Stop ` -WarningAction SilentlyContinue + # Verify connection + $web = Get-PnPWeb -ErrorAction Stop + if (-not $web) { + throw "Failed to connect to SharePoint site" + } + return $true } catch {