feat: Enhance SharePoint connection with error handling and verification

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 15:12:27 -08:00
parent 4759e7754e
commit 321d07f217

View File

@ -39,10 +39,20 @@ function Connect-SharePoint {
throw "Please enter a Site URL" throw "Please enter a Site URL"
} }
# Simplified interactive auth # Disconnect any existing connection first
Connect-PnPOnline -Url $siteUrl -Interactive ` Disconnect-PnPOnline -ErrorAction SilentlyContinue
# Use modern authentication with device code flow
Connect-PnPOnline -Url $siteUrl -Interactive -ForceAuthentication `
-ErrorAction Stop `
-WarningAction SilentlyContinue -WarningAction SilentlyContinue
# Verify connection
$web = Get-PnPWeb -ErrorAction Stop
if (-not $web) {
throw "Failed to connect to SharePoint site"
}
return $true return $true
} }
catch { catch {