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) {
|
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 {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user