fix: Correct SharePoint site lookup in Get-FolderBrowser function

This commit is contained in:
Bobby Abellana (aider) 2025-02-19 15:45:07 -08:00
parent 3d170f3652
commit d3ffe1098a

View File

@ -112,17 +112,17 @@ function Get-FolderBrowser {
try {
# Get site ID first
$siteUrl = $script:txtSiteUrl.Text.TrimEnd('/')
# Extract site path from URL
$sitePathMatch = $siteUrl -match "sharepoint\.com(.*)"
if (-not $sitePathMatch) {
# Extract hostname and site path from URL
if ($siteUrl -match "https://([^/]+)(/.*)") {
$hostname = $matches[1]
$sitePath = $matches[2]
} else {
throw "Invalid SharePoint URL format"
}
$sitePath = $matches[1]
# Get site directly using path
$site = Get-MgSite -SiteId "root" -Property "siteCollection,webUrl,id" -ErrorAction Stop
$site = Get-MgSite -SiteId $site.Id -Property "siteCollection,webUrl,id" -ErrorAction Stop `
-Filter "startswith(webUrl, '$siteUrl')"
# Get the site using hostname and path
$site = Get-MgSite -Filter "siteCollection/hostname eq '$hostname' and startsWith(webUrl, '$siteUrl')" -ErrorAction Stop
if (-not $site) {
throw "Site not found at $siteUrl"