From 497126d138c3ab5e10380ef1e270c3cb9f976b2e Mon Sep 17 00:00:00 2001 From: David Yoder Date: Fri, 23 Feb 2024 17:05:49 -0500 Subject: [PATCH] minor updates --- Get-BackupCapacityPlanningData.ps1 | 36 +++++++++++++----------------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Get-BackupCapacityPlanningData.ps1 b/Get-BackupCapacityPlanningData.ps1 index 16b1e7e..cf86ea1 100644 --- a/Get-BackupCapacityPlanningData.ps1 +++ b/Get-BackupCapacityPlanningData.ps1 @@ -17,7 +17,12 @@ Function Add-UserProfilePaths { # Iterate over each $profilePath and join it with the supplied $Path ForEach ( $profilePath in $UserProfilePaths ) { - Update-ListOfPaths -List $List -Path $(Join-Path -Path $profilePath -ChildPath $($Path -split '%')[2]) + + # Build the path we're trying to add + $path = $(Join-Path -Path $profilePath -ChildPath $($Path -split '%')[2]) + + # Only add the path if it exists (domain computers may have many invalid/old user accounts with nonexistant paths) + If ( Test-Path $path ) { Update-ListOfPaths -List $List -Path $path } } } @@ -36,9 +41,15 @@ Import-MSP360Module # Get all backup plans $BackupPlans = Get-MBSBackupPlan -OutputType Raw +# Track the number of processed backup plans so we can put line breaks between them in the output +$planIter = 0 + # Iterate over all backup plans ForEach ( $plan in $BackupPlans ) { + # Add a line break in the output if we've already processed a backup plan + If ( $planIter -gt 0 ) { Write-Output "`n" } + # Function to process each file Function ProcessFile { param([System.IO.FileInfo]$File) @@ -73,7 +84,7 @@ ForEach ( $plan in $BackupPlans ) { [System.Collections.Hashtable]$FilteredFiles = @{} [System.Collections.Hashtable]$IncludedFiles = @{} - # Get all included items from older plan format + # Get all included items from plan If ( $null -ne $plan.Items ) { ForEach ( $obj in $plan.Items ) { ForEach ( $path in $obj.PlanItem.Path ) { @@ -81,14 +92,8 @@ ForEach ( $plan in $BackupPlans ) { } } } - ## Get all included items from newer plan format - #If ( $null -ne $plan.BackupItem ) { - # ForEach ( $path in $plan.BackupItem ) { - # Use-Path -List $IncludedPaths -Path $path - # } - #} - # Get all excluded items from older plan format + # Get all excluded items from plan If ( $null -ne $plan.ExcludedItems ) { ForEach ( $obj in $plan.ExcludedItems ) { ForEach ( $path in $obj.PlanItem.Path ) { @@ -97,20 +102,13 @@ ForEach ( $plan in $BackupPlans ) { } } - ## Get all excluded items from newer plan format - #If ( $null -ne $plan.ExcludeItem ) { - # ForEach ( $path in $plan.ExcludeItem ) { - # Use-Path -List $ExcludedPaths -Path $path - # } - #} - # Print all paths in $IncludedPaths If ( $IncludedPaths.Length -gt 0 ) { Write-Output "Paths to backup:" ForEach ( $path in ($IncludedPaths | Sort-Object) ) { Write-Output $path } } - # Define $MaxFileSize if it exists, or set it to the max value of a long to bypass it + # Define $MaxFileSize if it exists, or set it to the default value if it can't be obtained If ( $null -ne $plan.MaxFileSize ) { $MaxFileSize = $plan.MaxFileSize } Else { $MaxFileSize = [long]::MaxValue } # Process each path in $IncludedPaths @@ -150,7 +148,5 @@ ForEach ( $plan in $BackupPlans ) { Write-Output $file.Name } } - - # Print a newline after each plan - Write-Output "`n" + $planIter++ }