72 lines
2.4 KiB
PowerShell
72 lines
2.4 KiB
PowerShell
#Script créé par Nicolas Lang - Sous licence CC-BY-SA
|
|
#https://nicolaslang.fr
|
|
|
|
|
|
Function Get-VMBackupsizes
|
|
{
|
|
#ajout du Snappin veeam
|
|
try {
|
|
Add-PSSnapin VeeamPSSnapin -ErrorAction Stop
|
|
}
|
|
catch {
|
|
exit 10
|
|
}
|
|
#récupération des backups
|
|
$backups = Get-VBRBackup
|
|
#récupération des jobs
|
|
$jobs = Get-VBRJob
|
|
#création d'un tableau
|
|
$array = New-Object System.collections.arraylist
|
|
#pour chaque backup dans la liste des backups
|
|
foreach ($backup in $backups)
|
|
{
|
|
#si le job avec le même ID possède une planification...
|
|
if ($($jobs | Where-Object {$_.id -eq $backup.JobId}).isScheduleEnabled -eq $true)
|
|
{
|
|
#définition d'une variable à "oui"
|
|
$isScheduled = "Oui"
|
|
}
|
|
else
|
|
{
|
|
#sinon à $false
|
|
$isScheduled = "Non"
|
|
}
|
|
#Recherche du job dont l'id est le même que l'id de job dans le backup en cours
|
|
$thisjob = $jobs | Where-Object {$_.id -eq $backup.info.jobid}
|
|
if ($thisjob -ne $null)
|
|
{
|
|
#Recherche des objets dans le job en question
|
|
$jobobject = Get-VBRJobObject $thisjob
|
|
}
|
|
else
|
|
{
|
|
$jobobject = $null
|
|
}
|
|
#Recherche des Objects In Backup et selection de vmname, calcul de la taille et des infos
|
|
|
|
$thisbackup = $backup.getlastoibs() | Select-Object -Property vmname,@{Name = "Size_calc"; Expression = {[math]::Round($($_.approxsize / 1024 / 1024 / 1024),2)}},info | sort -Property vmname
|
|
|
|
|
|
#pour chaque Object in Backup
|
|
foreach ($entry in $thisbackup)
|
|
{
|
|
#Recherche des objets dans le job en cours dont l'objectid est le même que l'id de l'Object in Backup actuel
|
|
$thisjobobject = $jobobject | Where-Object {$_.info.objectid -eq $entry.info.objectid}
|
|
#si ce jobobject n'est pas exclus
|
|
if(!$thisjobobject.isexcluded)
|
|
{
|
|
$null = $array.add([pscustomobject]@{
|
|
"VM" = $entry.vmName
|
|
"Active" = $isScheduled
|
|
"Job" = $backup.Name
|
|
"JobPath" = $backup.DirPath.ToString()
|
|
"JobRepository" = $backup.GetRepositoryName()
|
|
"Size" = $entry.size_calc
|
|
"LastPointCreation" = $backup.LastPointCreationTime
|
|
})
|
|
}
|
|
}
|
|
}
|
|
$array = $array | Sort-Object -Property Job,vm
|
|
return $array
|
|
} |