diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 37cfb35..30bd1ce 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -72,8 +72,12 @@ function List-XlsFiles { # Get the folder ID first # Construct the correct URI for the folder # Remove the /sites/tax/Shared Documents part from the folder path - $relativePath = $folderPath.Replace("/sites/tax/Shared Documents/", "") - $folderUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:$($relativePath)" + $relativePath = $folderPath.Replace("/sites/tax/Shared Documents/", "").TrimStart("/") + + # URL encode the relative path + $encodedPath = [System.Web.HttpUtility]::UrlEncode($relativePath) + + $folderUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:/$encodedPath" $script:txtStatus.Text += "Folder URI: $folderUri`n" try { $folderItem = Invoke-MgGraphRequest -Method GET -Uri $folderUri -ErrorAction Stop