From d3e21955da799dcd97dd48fb5a7d6539a345f4ad Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Wed, 19 Feb 2025 15:46:33 -0800 Subject: [PATCH] fix: Update Graph API permissions and site access method in folder browser --- GraphConfig.ps1 | 2 ++ SharePointFunctions.ps1 | 17 +++++------------ 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/GraphConfig.ps1 b/GraphConfig.ps1 index 0b70aa7..b0e39f6 100644 --- a/GraphConfig.ps1 +++ b/GraphConfig.ps1 @@ -5,6 +5,8 @@ $script:graphConfig = @{ Scopes = @( "Files.ReadWrite.All" "Sites.ReadWrite.All" + "Sites.Read.All" + "Sites.Selected" ) } diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index faec17c..c05bcb8 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -113,25 +113,18 @@ function Get-FolderBrowser { # Get site ID first $siteUrl = $script:txtSiteUrl.Text.TrimEnd('/') - # Extract hostname and site path from URL - if ($siteUrl -match "https://([^/]+)(/.*)") { - $hostname = $matches[1] - $sitePath = $matches[2] - } else { - throw "Invalid SharePoint URL format" - } - - # Get the site using hostname and path - $site = Get-MgSite -Filter "siteCollection/hostname eq '$hostname' and startsWith(webUrl, '$siteUrl')" -ErrorAction Stop + # Get site directly using the URL + $encodedUrl = [System.Web.HttpUtility]::UrlEncode($siteUrl) + $site = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/sites/sutterhill.sharepoint.com:/sites/tax" -ErrorAction Stop if (-not $site) { throw "Site not found at $siteUrl" } - $script:txtStatus.Text += "Found site: $($site.WebUrl)`n" + $script:txtStatus.Text += "Found site: $($site.webUrl)`n" # Get drive (document library) - $drives = Get-MgSiteDrive -SiteId $site.Id + $drives = Get-MgSiteDrive -SiteId $site.id # Handle "Shared Documents" special case $libraryName = if ($script:txtProdLib.Text -eq "Shared Documents") { "Documents"