feat: Enhance SharePoint web login with retries, timeout, and verification
This commit is contained in:
parent
dc9ee3ccc1
commit
dacdc42716
@ -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"
|
||||
|
||||
Loading…
Reference in New Issue
Block a user