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
|
# Ignore disconnection errors
|
||||||
}
|
}
|
||||||
|
|
||||||
# Use Azure Management authentication
|
# Use web login with additional parameters for stability
|
||||||
Connect-PnPOnline -Url $siteUrl -UseWebLogin `
|
Connect-PnPOnline -Url $siteUrl `
|
||||||
|
-UseWebLogin `
|
||||||
-ErrorAction Stop `
|
-ErrorAction Stop `
|
||||||
-WarningAction SilentlyContinue
|
-WarningAction SilentlyContinue `
|
||||||
|
-RetryCount 3 `
|
||||||
|
-RetryWait 3 `
|
||||||
|
-Timeout 300
|
||||||
|
|
||||||
|
Start-Sleep -Seconds 2 # Give the web login time to complete
|
||||||
|
|
||||||
# Verify connection
|
# Verify connection with timeout
|
||||||
$web = Get-PnPWeb -ErrorAction Stop
|
$timeoutSeconds = 30
|
||||||
if (-not $web) {
|
$startTime = Get-Date
|
||||||
throw "Failed to connect to SharePoint site"
|
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 {
|
catch {
|
||||||
$script:txtStatus.Text += "Connection Error: $($_.Exception.Message)`n"
|
$script:txtStatus.Text += "Connection Error: $($_.Exception.Message)`n"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user