fix: Add null checks and error handling in Get-XlsFilesRecursive
This commit is contained in:
parent
cc799c7d68
commit
bbf46c9eb8
@ -280,8 +280,24 @@ function Get-XlsFilesRecursive {
|
|||||||
|
|
||||||
$allFiles = @()
|
$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
|
# 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) {
|
foreach ($item in $items) {
|
||||||
$script:txtStatus.Text += "Checking item: $($item.Name)`n"
|
$script:txtStatus.Text += "Checking item: $($item.Name)`n"
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user