From c955fed48905c10b1b0b8980bc5865b24df4f455 Mon Sep 17 00:00:00 2001 From: "Bobby Abellana (aider)" Date: Fri, 21 Feb 2025 09:22:25 -0800 Subject: [PATCH] fix: Improve folder path resolution and error handling in List-XlsFiles --- SharePointFunctions.ps1 | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 16cf38d..af98431 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -70,7 +70,14 @@ function List-XlsFiles { if (-not [string]::IsNullOrWhiteSpace($folderPath)) { $script:txtStatus.Text += "Searching in folder: $folderPath`n" # Get the folder ID first - $folderItem = Invoke-MgGraphRequest -Method GET -Uri "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:$($folderPath)" + # Construct the correct URI for the folder + $folderUri = "https://graph.microsoft.com/v1.0/drives/$($drive.Id)/root:$($folderPath)" + $script:txtStatus.Text += "Folder URI: $folderUri`n" + try { + $folderItem = Invoke-MgGraphRequest -Method GET -Uri $folderUri -ErrorAction Stop + } catch { + throw "Folder not found: $($_.Exception.Message)" + } $items = Get-MgDriveItemChild -DriveId $drive.Id -DriveItemId $folderItem.id } else { $script:txtStatus.Text += "Searching in root folder`n"