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

@ -38,11 +38,21 @@ function Connect-SharePoint {
if (-not $siteUrl) { if (-not $siteUrl) {
throw "Please enter a Site URL" throw "Please enter a Site URL"
} }
# Disconnect any existing connection first
Disconnect-PnPOnline -ErrorAction SilentlyContinue
# Simplified interactive auth # Use modern authentication with device code flow
Connect-PnPOnline -Url $siteUrl -Interactive ` 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 {