feat: Enhance SharePoint connection with error handling and verification
This commit is contained in:
parent
4759e7754e
commit
321d07f217
@ -38,11 +38,21 @@ function Connect-SharePoint {
|
||||
if (-not $siteUrl) {
|
||||
throw "Please enter a Site URL"
|
||||
}
|
||||
|
||||
# Disconnect any existing connection first
|
||||
Disconnect-PnPOnline -ErrorAction SilentlyContinue
|
||||
|
||||
# Simplified interactive auth
|
||||
Connect-PnPOnline -Url $siteUrl -Interactive `
|
||||
# Use modern authentication with device code flow
|
||||
Connect-PnPOnline -Url $siteUrl -Interactive -ForceAuthentication `
|
||||
-ErrorAction Stop `
|
||||
-WarningAction SilentlyContinue
|
||||
|
||||
# Verify connection
|
||||
$web = Get-PnPWeb -ErrorAction Stop
|
||||
if (-not $web) {
|
||||
throw "Failed to connect to SharePoint site"
|
||||
}
|
||||
|
||||
return $true
|
||||
}
|
||||
catch {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user