feat: Enhance SharePoint web login with retries, timeout, and verification

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 15:16:43 -08:00
parent dc9ee3ccc1
commit dacdc42716

View File

@ -47,18 +47,34 @@ function Connect-SharePoint {
# Ignore disconnection errors
}
# Use Azure Management authentication
Connect-PnPOnline -Url $siteUrl -UseWebLogin `
# Use web login with additional parameters for stability
Connect-PnPOnline -Url $siteUrl `
-UseWebLogin `
-ErrorAction Stop `
-WarningAction SilentlyContinue
-WarningAction SilentlyContinue `
-RetryCount 3 `
-RetryWait 3 `
-Timeout 300
# Verify connection
$web = Get-PnPWeb -ErrorAction Stop
if (-not $web) {
throw "Failed to connect to SharePoint site"
Start-Sleep -Seconds 2 # Give the web login time to complete
# Verify connection with timeout
$timeoutSeconds = 30
$startTime = Get-Date
while ((Get-Date) -lt $startTime.AddSeconds($timeoutSeconds)) {
try {
$web = Get-PnPWeb -ErrorAction Stop
if ($web) {
return $true
}
}
catch {
Start-Sleep -Seconds 2
continue
}
}
return $true
throw "Timeout waiting for SharePoint connection"
}
catch {
$script:txtStatus.Text += "Connection Error: $($_.Exception.Message)`n"