diff --git a/SharePointFunctions.ps1 b/SharePointFunctions.ps1 index 98acc77..ed741cc 100644 --- a/SharePointFunctions.ps1 +++ b/SharePointFunctions.ps1 @@ -280,8 +280,24 @@ function Get-XlsFilesRecursive { $allFiles = @() + # Check if DriveId or DriveItemId is null or empty + if ([string]::IsNullOrEmpty($DriveId)) { + $script:txtStatus.Text += "Error: DriveId is null or empty`n" + return $allFiles + } + if ([string]::IsNullOrEmpty($DriveItemId)) { + $script:txtStatus.Text += "Error: DriveItemId is null or empty`n" + return $allFiles + } + # Get items in the current folder - $items = Get-MgDriveItemChild -DriveId $DriveId -DriveItemId $DriveItemId + try { + $items = Get-MgDriveItemChild -DriveId $DriveId -DriveItemId $DriveItemId -ErrorAction Stop + } + catch { + $script:txtStatus.Text += "Error getting items: $($_.Exception.Message)`n" + return $allFiles + } foreach ($item in $items) { $script:txtStatus.Text += "Checking item: $($item.Name)`n"