PowerShell script exchange
Post Reply
WienerHausberge
Novice
Posts: 6
Liked: 3 times
Joined: Nov 21, 2022 8:41 am
Full Name: WH
Contact:

List VMs one by one

Post by WienerHausberge »

Dear Veeam-Community,
currently I'm trying to list the name and the backup size for every single client and vm with the help of a powershell script.
It works fine until the platform is listed as "VMware". Then my script always lists all the vms as one. The backup size is still correct.
As long as the platform is listed as "Windows" or "Linux all the clients listed below the tageted backup-job are listed one by one.
I would like to get that output for the "VMware" as well.
I hope you can understand what I was trying to explain.
Thanks for reading this and for your help :)

This is my code so far:

Code: Select all

$backups = Get-VBRBackup

$size = 0;

foreach($backup in $backups) {
	$backupName = ($backup | Select -ExpandProperty JobName);
	
	$nameList = ($backup | Select @(n="vm";e={$_.GetObjectOibsAll() | %{@($_.name,"")}}} | Select -ExpandProperty vm);
	
	$restorePoints = $backup.getAllStorages() | sort CreationTime -Descending
	
	foreach($restorePoint in $restorePoints) {
		$sizePoint = ($point | Select-Object -ExpandProperty stats | Select -ExpandProperty BackupSize);
		$size += $sizePoint
	}
	
	$size = [math]::Round(($size / 1024 /1024 /1024 /1024), 4);
	
	Write-Host "--------------------------------------"
	Write-Host "Backup Name: "$backupname
	Write-Host "Names of listed Clients: "$nameList
	Write-Host "Backup Size: "$size"
	Write-Host "--------------------------------------"
	
}

Cheers and best regards!
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: List VMs one by one

Post by david.domask »

Hi @WienerHausberge,

Right now it's summing up all of your backup sizes into the $size array, so that's why the VMware backups (which will have multiple machines as opposed to the ComputerBackups) will be "grouped".

Just to confirm, how do you want the size of backup to be understood? Just the size of a full backup or the total size of every single backup file associated with a backup?
David Domask | Product Management: Principal Analyst
WienerHausberge
Novice
Posts: 6
Liked: 3 times
Joined: Nov 21, 2022 8:41 am
Full Name: WH
Contact:

Re: List VMs one by one

Post by WienerHausberge »

Hey @david.domask,
thanks for you quick reply.
I hope this picture can clarify a bit more, what I am looking for.

Image

If I got it right, then it's the total size of every single backup file associated with the backup?

Cheers!
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: List VMs one by one

Post by david.domask » 1 person likes this post

Hi @WienerHausberge,

I think I get what you're going for.

I'll leave the formatting/editing of the table data up to you, but I'd try it like this:

Code: Select all

function Get-VBRStorageFileStats {
	param(
		[Veeam.Backup.Core.COib]$rp
		)
	$FileStats = $rp.FindStorage().Stats.BackupSize
	Return $FileStats
}
	
$Backups = Get-VBRBackup
$ReportData = @()

ForEach($b in $Backups){
	$JobName = $b.JobName
	$JobType = $b.JobType
	$RestorePoints = Get-VBRRestorePoint -Backup $b | Sort-Object -Property CreationTime -Descending
	Foreach($r in $RestorePoints){
		$storageSize = Get-VBRStorageFileStats -rp $r
		$BackupData = [PSCustomObject] @{
			JobName = $JobName
			JobType = $JobType
			MachineName = $r.Name
			BackupFileSize = $storageSize
			RestorePointDate = $r.CreationTime
		}
		$ReportData += $BackupData
	}
}
You can see an example output here:

Code: Select all

PS C:\Program Files\Veeam\Backup and Replication\Backup> $ReportData|Format-Table

JobName                                          JobType MachineName          BackupFileSize RestorePointDate
-------                                          ------- -----------          -------------- ----------------
ps-test-agent                              EpAgentBackup DDOM-VEEAM-RB4              3301376 2/28/2023 3:26:05 PM
ps-test-agent                              EpAgentBackup DDOM-VEEAM-RB4              3825664 2/24/2023 1:46:05 PM
gfs-test_clone1                               BackupSync DDom-TinyVM_replica         2228224 1/30/2023 10:01:45 PM
gfs-test_clone1                               BackupSync ddom-tinyvm                 2228224 1/30/2023 10:00:47 PM
gfs-test_clone1                               BackupSync DDom-TinyVM_replica         2199552 1/26/2023 10:01:49 PM
gfs-test_clone1                               BackupSync ddom-tinyvm                 2199552 1/26/2023 10:00:46 PM
gfs-test_clone1                               BackupSync DDom-TinyVM_replica         2224128 1/26/2023 7:50:09 PM
gfs-test_clone1                               BackupSync ddom-tinyvm                 2224128 1/26/2023 8:01:36 AM
Backup Copy Job 2                 SimpleBackupCopyPolicy SKur-linux-dummy-1        814661405 2/20/2023 5:11:25 PM
ddom-tinyvm_2022-11-24_2025-11-24                 Backup ddom-tinyvm                 1634304 11/24/2022 8:01:28 AM
Few comments:

1. I left the BackupFileSize in bytes because I test with tiny VMs (Thin Disk machines with no actual OS), you will want to change the line with BackupFileSize = $storageSize to be like:

BackupFileSize = $storageSize/1GB

That will display it in Gigabytes; Terabytes and so on are similar syntax. I change it in the PSCustomObject as I want to keep the original data intact in case you want to edit the script.

2. Right now it's a bit verbose on the output as I'm not sure what else you want :) You can add properties (or remove) on the PSCustomObject to your heart's desire.

3. My framework above is suitable for output to CSV with Export-CSV cmdlet in Powershell; it's convenient to export it to other systems easily. Export-JSON should work also here.

4. I break out the StorageSize format into a function as it's easier to edit, and for any other properties where you need to call another cmdlet or method to get the data, I advise do it there too. This also means that if some backup objects maybe have properties other's don't, it's a lot easier/cleaner to introduce a meaningful IF statement to only run the function on those objects.

I'm not confident I hit everything you wanted, and I know the framework's basic output likely isn't formatted as pretty as you want, but if you have troubles getting it to look like you're hoping, just update and we can help :)
David Domask | Product Management: Principal Analyst
WienerHausberge
Novice
Posts: 6
Liked: 3 times
Joined: Nov 21, 2022 8:41 am
Full Name: WH
Contact:

Re: List VMs one by one

Post by WienerHausberge » 1 person likes this post

Hey @david.domask,
this really looks like the thing I'm trying to do. I just tried out your code but still need some time to adjust it to my exact wantings.
I'll let you know as soon as I'm done.
But already, let me say 'thank you so much'!

Much love!
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: List VMs one by one

Post by david.domask »

Glad I could help get you started here @WienerHausberge!

Let us know how it goes :) (and share the script in the end if you're willing ;) )
David Domask | Product Management: Principal Analyst
WienerHausberge
Novice
Posts: 6
Liked: 3 times
Joined: Nov 21, 2022 8:41 am
Full Name: WH
Contact:

Re: List VMs one by one

Post by WienerHausberge » 1 person likes this post

I can confirm now, that your script helped me getting what I needed. Thanks so much! When I'm done with my script, I'll let you guys know and share it here :)
Cheers!
WienerHausberge
Novice
Posts: 6
Liked: 3 times
Joined: Nov 21, 2022 8:41 am
Full Name: WH
Contact:

Re: List VMs one by one

Post by WienerHausberge » 1 person likes this post

Sorry, for the spam, but is it possible to simply exchange:

$FileStats = $rp.FindStorage().Stats.BackupSize

with

$FileStats = $rp.FindStorage().Stats.DataSize

to get the Data Size? I don't think so, right?

Best regards
david.domask
Veeam Software
Posts: 1226
Liked: 323 times
Joined: Jun 28, 2016 12:12 pm
Contact:

Re: List VMs one by one

Post by david.domask »

Heya! Posts are free so spam away as long as it's actual questions/content ;)

Aha, you're quite correct. You can return anything from that property. If you're going to pull a few, you might want to just do the FindStorage() call once with

$FileStats = $rp.FindStorage().Stats

Then make two new objects that pull their data from $FileStats like:

$BackupSize = $FileStats.BackupSize
$Datasize = $FileStats.DataSize

This saves you having to call FindStorage() multiple times.
David Domask | Product Management: Principal Analyst
Post Reply

Who is online

Users browsing this forum: No registered users and 16 guests