From 368911a19d407bb54f28624061601069dd89f15c Mon Sep 17 00:00:00 2001 From: Nicolas Lang Date: Sun, 17 Dec 2023 19:57:13 +0100 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20script?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Veeam/get_vm_backup_size.ps1 | 72 ++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 Veeam/get_vm_backup_size.ps1 diff --git a/Veeam/get_vm_backup_size.ps1 b/Veeam/get_vm_backup_size.ps1 new file mode 100644 index 0000000..168e4ec --- /dev/null +++ b/Veeam/get_vm_backup_size.ps1 @@ -0,0 +1,72 @@ +#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 +} \ No newline at end of file