From 038b8f26857e18397c4c97b20833d16905bd15ec Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 23 Feb 2024 00:30:42 -0500 Subject: [PATCH] better handle missing MaxFileSize prop --- Get-BackupCapacityPlanningData.ps1 | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Get-BackupCapacityPlanningData.ps1 b/Get-BackupCapacityPlanningData.ps1 index 634a4f9..2536c2c 100644 --- a/Get-BackupCapacityPlanningData.ps1 +++ b/Get-BackupCapacityPlanningData.ps1 @@ -43,13 +43,14 @@ ForEach ( $plan in $BackupPlans ) { # Function to process each file Function ProcessFile { param([System.IO.FileInfo]$File) + Switch ( $File ) { # Filter out if name matches an excluded path { $null -ne ($ExcludedPaths | Where-Object { $File.FullName.Replace('\','\\') -match $_.Replace('\','\\') }) } { Update-FilteredFiles $File } # Filter out if file size is greater than plan maximum - { $File.Length -gt $plan.MaxFileSize } { Update-FilteredFiles $File } + { $File.Length -gt $MaxFileSize } { Update-FilteredFiles $File } # Add item to $IncludeFiles default { $IncludedFiles.Add($item.FullName, $item.Length) | Out-Null } @@ -110,6 +111,9 @@ ForEach ( $plan in $BackupPlans ) { ForEach ( $path in $IncludedPaths ) { Write-Output $path } } + # Define $MaxFileSize if it exists, or set it to the max value of a long to bypass it + If ( $null -ne $plan.MaxFileSize ) { $MaxFileSize = $plan.MaxFileSize } Else { $MaxFileSize = [long]::MaxValue } + # Process each path in $IncludedPaths ForEach ($path in $IncludedPaths ) { @@ -117,7 +121,7 @@ ForEach ( $plan in $BackupPlans ) { If ( !(Test-Path $path) ) { Continue } # If $path is an individual file, process it separately - $item = Get-Item -Path $path + $item = Get-Item -Path $path -ErrorAction SilentlyContinue If ( $item -is [System.IO.FileInfo] ) { ProcessFile $item ; Continue } # Get all children of $path