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 { try {
# Get site ID first # Get site ID first
$siteUrl = $script:txtSiteUrl.Text.TrimEnd('/') $siteUrl = $script:txtSiteUrl.Text.TrimEnd('/')
# Extract site path from URL
$sitePathMatch = $siteUrl -match "sharepoint\.com(.*)" # Extract hostname and site path from URL
if (-not $sitePathMatch) { if ($siteUrl -match "https://([^/]+)(/.*)") {
$hostname = $matches[1]
$sitePath = $matches[2]
} else {
throw "Invalid SharePoint URL format" throw "Invalid SharePoint URL format"
} }
$sitePath = $matches[1]
# Get the site using hostname and path
# Get site directly using path $site = Get-MgSite -Filter "siteCollection/hostname eq '$hostname' and startsWith(webUrl, '$siteUrl')" -ErrorAction Stop
$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')"
if (-not $site) { if (-not $site) {
throw "Site not found at $siteUrl" throw "Site not found at $siteUrl"