PowerShell script exchange
Post Reply
Moebius
Veeam ProPartner
Posts: 206
Liked: 28 times
Joined: Jun 09, 2009 2:48 pm
Full Name: Lucio Mazzi
Location: Reggio Emilia, Italy
Contact:

Listing all VMs and associated backup jobs

Post by Moebius »

Hello script gurus,
I'm looking for a PS script to produce an output file with the list of all VM existing on <datacenter> and the associated Veeam backup jobs, if any. Ideally the output file should look like this:

Code: Select all

VM1: JobA
VM2: JobB
VM3:
VM4: JobA, JobD
...
and so on. Or as an alternative, a list with all existing backup jobs and the associated VMs, but also the VMs that have no backup job associated. Something like this:

Code: Select all

JobA: VM1, VM4
JobB: VM2
JobD: VM4
...
*no job*: VM3
The output should be a text file, or the script output should be redirectable to a file.
I'm an absolute beginner with PowerShell and scripts. Any help would be appreciated.
dellock6
Veeam Software
Posts: 6137
Liked: 1928 times
Joined: Jul 26, 2009 3:39 pm
Full Name: Luca Dell'Oca
Location: Varese, Italy
Contact:

Re: Listing all VMs and associated backup jobs

Post by dellock6 »

Hi Lucio,
even if not the exact same thing, take a look at this thread:
http://forums.veeam.com/viewtopic.php?f=26&t=12714
the script lists all VM that have a backup in the last XX hours, so you can identify easily which VMs are not under backup. This is a part of your needs.

Luca.
Luca Dell'Oca
Principal EMEA Cloud Architect @ Veeam Software

@dellock6
https://www.virtualtothecore.com/
vExpert 2011 -> 2022
Veeam VMCE #1
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Listing all VMs and associated backup jobs

Post by tsightler »

And I do plan to extend that script with job information when I get a few minutes.
Moebius
Veeam ProPartner
Posts: 206
Liked: 28 times
Joined: Jun 09, 2009 2:48 pm
Full Name: Lucio Mazzi
Location: Reggio Emilia, Italy
Contact:

Re: Listing all VMs and associated backup jobs

Post by Moebius »

Thanks Luca and Tom. As a matter of fact I have already tried out, and partially used, both your scripts - but had missed yet the last contribution to that thread.
The problem in my case is that I have broadly divided the VMs into several groups and jobs:
- VMs to back up daily,
- VMs to back up weekly,
- VMs to back up monthly,
- VMs to back up every once in a while (no schedule, manual run).
So even having the option of encompassing xx hours or days worth of backups, the machines of the last group would be listed as not backed up.
Furthermore, I think I like better a script that lists protected VMs on the basis of which are currently included in my jobs, rather than on the basis of the past backup history. I believe it's a matter of preferences here.
So far I have assembled a bunch of scripts that give more or less the result I want. It does require some manual editing though, due to my almost non-existent knowledge of the PowerShell world.

Your scripts are great material to work on though. I'll follow that thread closely.
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Listing all VMs and associated backup jobs

Post by tsightler »

Right, the scripts somewhat perform different purposes. My script is designed more to find all VMs in the environment that are not protected either because they are not in a job (overlooked), or due to the fact that they are failing. Reporting simply on what VMs are in a job is also very difficult for people who create jobs based on parent objects such as folder, etc.

However, the Backup Status Report could easily be modified to include not just failed/warning jobs, but also successful jobs. That might be the best place to start for your report.
tsightler
VP, Product Management
Posts: 6009
Liked: 2842 times
Joined: Jun 05, 2009 12:57 pm
Full Name: Tom Sightler
Contact:

Re: Listing all VMs and associated backup jobs

Post by tsightler »

Moebius wrote:Furthermore, I think I like better a script that lists protected VMs on the basis of which are currently included in my jobs, rather than on the basis of the past backup history. I believe it's a matter of preferences here.
Regarding this portion, do you only add VMs to your jobs individually? If so, then that's a pretty easy use case, however, many, many customers choose to select container objects such as datastores or folders rather than individual VMs. This makes the script very complicated to determine which VMs are actually in a job, since I would then have to get the container object that are in the job, and then enumerate that object to find it's child VMs. Then I would have to take into account any possible exclusions, which can also be based on individual VMs or container objects.

On the other hand the session data from the last run would generally include all of the VMs that were backed up based on those enumerated objects so that why I selected that method as it was simply far easier to code and covered all user cases. Also, I wanted to catch cases where VMs were in a job, but failed since the idea was that it would be a scheduled report. It sounds like your use case is different enough but the overall concept is about the same.
Moebius
Veeam ProPartner
Posts: 206
Liked: 28 times
Joined: Jun 09, 2009 2:48 pm
Full Name: Lucio Mazzi
Location: Reggio Emilia, Italy
Contact:

Re: Listing all VMs and associated backup jobs

Post by Moebius »

Yes, I add most of the VMs individually. I have only one container added and I see what you mean.
I concur that the script I'm looking for would have some limitations, still it would fit my case. I'm just hoping somebody has some script fragments that I could use. I tried to do it myself, end I even believe my case would be pretty easy for a skilled person, but as mentioned my knowledge of PS is way too limited and I don't have enough time to dedicate to it... too bad!
Gav@GH
Influencer
Posts: 21
Liked: 15 times
Joined: Jul 20, 2012 12:27 am
Contact:

Re: Listing all VMs and associated backup jobs

Post by Gav@GH »

I have a basic script that reports on each job (the VM's in it and the current result), from the last backup session.

Currently just throws out a colourful but clunky write-host, so could do with some tabulation or HTML/email output.

Code: Select all

asnp "VeeamPSSnapIn" -ErrorAction SilentlyContinue

foreach($Job in (Get-VBRJob))
	{
	$Session = $Job.FindLastSession()
	if(!$Session){continue;}
	$Info = $Session.GetTaskSessions()
	
	$Success = ($info | ForEach-Object {$_} |
	Where-Object {$_.status -eq "Success"}) |
	Foreach-object {$_ | Select-Object @{Name="Job";Expression={$Job.Name}}, 
		@{Name="VM";Expression={$_.Name}}, 
		@{Name="Status";Expression={$_.Status}}, 
		@{Name="Start";Expression={$_.progress.starttime}}, 
		@{Name="Finish";Expression={$_.progress.stoptime}}| Format-List | Out-String}
	write-host -foregroundcolor Green $Success

	$Failed = ($info | ForEach-Object {$_} |
	Where-Object {$_.status -eq "Failed"}) |
	Foreach-object {$_ | Select-Object @{Name="Job";Expression={$Job.Name}},
		@{Name="VM";Expression={$_.Name}}, 
		@{Name="Status";Expression={$_.Status}}, 
		@{Name="Start";Expression={$_.progress.starttime}}, 
		@{Name="Finish";Expression={$_.progress.stoptime}},
		@{Name="Job Msg";Expression={$_.info.description}},
		@{Name="Reason";Expression={$_.GetDetails()}} | Format-List | Out-String}
	write-host -foregroundcolor Red $Failed

	$Pending = ($info | ForEach-Object {$_} |
	Where-Object {$_.status -eq "InProgress" -or $_.status -eq "Pending"}) |
	Foreach-object {$_ | Select-Object @{Name="Job";Expression={$Job.Name}},
		@{Name="VM";Expression={$_.Name}}, 
		@{Name="Status";Expression={$_.Status}}, 
		@{Name="Scheduled";Expression={$_.progress.starttime}} | Format-List | Out-String}
	write-host -foregroundcolor Yellow $Pending
	}
Gav@GH
Influencer
Posts: 21
Liked: 15 times
Joined: Jul 20, 2012 12:27 am
Contact:

Re: Listing all VMs and associated backup jobs

Post by Gav@GH »

I've just put up a post which produces some good reports on Veeam, including all of the VMs and their job details

http://forums.veeam.com/viewtopic.php?f=26&t=13422
artecu
Influencer
Posts: 23
Liked: 2 times
Joined: Mar 23, 2012 6:52 am
Full Name: Andrew R Tilbury
Contact:

Re: Listing all VMs and associated backup jobs

Post by artecu »

Hi Gavin.
You are a credit to us all. Thanks for sharing these scripts. Being a complete Powershell novice, I have struggled to get anywhere along these lines... but running this was easy! I do get a prompt for [D] Do not Run [R] Run once etc for each script but I can live with that... the report is awesome.
The backup storage space (and Unprotected Vms scripts) fill a big gap for me. I hope Veeam decide to add a column in the Repositories pane of "Infrastructure" to report free space- as this should be at our fingertips every day IMHO.
:? I don't suppose you have a script that will allow me to run an "on demand" backup of a VM that is already covered by an existing job? It would involve removing all folders and adding a single vm to the job, running it and then replacing the folder, exclusions etc?? Its for doing on the spot incrementals without having to waste disk space/time for Full backup etc etc. Again, this would be a nice "right click of the vm" feature to add to a future VeeamBR release.

Thanks
Andy
Gav@GH
Influencer
Posts: 21
Liked: 15 times
Joined: Jul 20, 2012 12:27 am
Contact:

Re: Listing all VMs and associated backup jobs

Post by Gav@GH » 1 person likes this post

Any ps1 files that have been sourced from another computer (ie the Internet), need to be 'Unblocked'. Right click on the file and check the Properties. This will get rid of the 'Do not run' prompts.

Sorry, do not have scripts the work with the jobs at ts stage.
artecu
Influencer
Posts: 23
Liked: 2 times
Joined: Mar 23, 2012 6:52 am
Full Name: Andrew R Tilbury
Contact:

Re: Listing all VMs and associated backup jobs

Post by artecu »

Thanks Again. All good now.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 20 guests