Get-VeeamBackupChain.ps1
<#PSScriptInfo .VERSION 1.0.1 .GUID 9fb312be-5599-45d2-98be-eda3b5758406 .AUTHOR saw-friendship@yandex.ru .COMPANYNAME .COPYRIGHT saw-friendship .TAGS saw-friendship Veeam Report BackUpJob Chain .LICENSEURI .PROJECTURI https://sawfriendship.wordpress.com/ .ICONURI .EXTERNALMODULEDEPENDENCIES .REQUIREDSCRIPTS .EXTERNALSCRIPTDEPENDENCIES .RELEASENOTES #> <# .DESCRIPTION Build report for Veeam BackupJob chains #> if(!(Get-PSSnapin -Name VeeamPSSnapin -ErrorAction SilentlyContinue)){ if((Get-PSSnapin -Registered -Name VeeamPSSnapin -ErrorAction SilentlyContinue)){ Add-PSSnapin VeeamPSSnapin } else {Write-Warning "VeeamPSSnapin not exist"; break} } $join = ';' $Jobs = Get-VBRJob $Jobs | Add-Member -MemberType NoteProperty -Name NextJobIdInScheduleChain -Value $Null -Force $Jobs | Add-Member -MemberType NoteProperty -Name ChainDescription -Value $Null -Force $Jobs | Add-Member -MemberType NoteProperty -Name Object -Value $Null -Force $Jobs | % {$_.Object = $_.GetObjectsInJob().Location} $Jobs | % {$id = $_.id; $_.NextJobIdInScheduleChain = ($Jobs | ? {$_.PreviousJobIdInScheduleChain -eq $id}).id} $JobsHash_ID_Name = @{} $JobsHash_ID_Object = @{} $Chains = [ordered]@{} $Jobs | % {$JobsHash_ID_Name.Add($_.id,$_.Name)} $Jobs | % {$JobsHash_ID_Object.Add($_.id,$_)} $Jobs | ? {!$_.PreviousJobIdInScheduleChain -and $_.NextJobIdInScheduleChain} | % { $Chains.Add( ($_.Name),([ordered]@{0=$_.id}) ) } $Chains.Keys | % { $Chain = $_ do { $Child = $Jobs | ? {$Chains[$Chain][-1] -contains $_.PreviousJobIdInScheduleChain} if ( $Child.id ) { $Chains[$Chain].Add( $Chains[$Chain].count , $Child.id ) } } while ($Child.id) 0..($Chains[$Chain].Count-1) | % { $level = $_ $NewDescription = "Root= $Chain; Level= $level; LevelChilds= $([string]($JobsHash_ID_Name[$Chains[$Chain][$level]] -join ', ')); LevelChildsID= $([string]($Chains[$Chain][$level] -join ', '))" $JobsHash_ID_Name[$Chains[$Chain][$level]] | % { [pscustomobject][ordered]@{ 'JobName' = $_ 'Root' = $Chain 'Level' = $level 'LevelChilds' = ($JobsHash_ID_Name[$Chains[$Chain][$level]]) 'LevelChildsID' = ($Chains[$Chain][$level]) 'ShortDescription' = $Chain + ' - ' + $level.ToString().PadLeft(4,'0') 'Object' = $JobsHash_ID_Object[$Chains[$Chain][$level]].Object -join $join 'Description' = $NewDescription } } } } |