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"