From d3ffe1098af2836fca7da6a7f340c0246500dc87 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Wed, 19 Feb 2025 15:45:07 -0800 Subject: [PATCH] fix: Correct SharePoint site lookup in Get-FolderBrowser function --- SharePointFunctions.ps1 | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 93d1408..faec17c 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -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"