Listing all VMs and associated backup jobs

PowerShell script exchange

Listing all VMs and associated backup jobs

Veeam Logoby Moebius » Fri Jul 20, 2012 11:54 am

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.
Moebius
Veeam ProPartner
 
Posts: 139
Liked: 17 times
Joined: Tue Jun 09, 2009 2:48 pm
Location: Reggio Emilia, Italy
Full Name: Lucio Mazzi

Re: Listing all VMs and associated backup jobs

Veeam Logoby dellock6 » Fri Jul 20, 2012 2:18 pm

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
EMEA Cloud Architect @ Veeam Software

@dellock6
http://www.virtualtothecore.com
vExpert 2011-2012-2013-2014-2015-2016
Veeam VMCE #1
dellock6
Veeam Software
 
Posts: 5052
Liked: 1333 times
Joined: Sun Jul 26, 2009 3:39 pm
Location: Varese, Italy
Full Name: Luca Dell'Oca

Re: Listing all VMs and associated backup jobs

Veeam Logoby tsightler » Fri Jul 20, 2012 2:37 pm

And I do plan to extend that script with job information when I get a few minutes.
tsightler
Veeam Software
 
Posts: 4769
Liked: 1738 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Listing all VMs and associated backup jobs

Veeam Logoby Moebius » Fri Jul 20, 2012 9:25 pm

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.
Moebius
Veeam ProPartner
 
Posts: 139
Liked: 17 times
Joined: Tue Jun 09, 2009 2:48 pm
Location: Reggio Emilia, Italy
Full Name: Lucio Mazzi

Re: Listing all VMs and associated backup jobs

Veeam Logoby tsightler » Fri Jul 20, 2012 10:20 pm

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
Veeam Software
 
Posts: 4769
Liked: 1738 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Listing all VMs and associated backup jobs

Veeam Logoby tsightler » Sat Jul 21, 2012 3:01 am

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.
tsightler
Veeam Software
 
Posts: 4769
Liked: 1738 times
Joined: Fri Jun 05, 2009 12:57 pm
Full Name: Tom Sightler

Re: Listing all VMs and associated backup jobs

Veeam Logoby Moebius » Sat Jul 21, 2012 7:17 am

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!
Moebius
Veeam ProPartner
 
Posts: 139
Liked: 17 times
Joined: Tue Jun 09, 2009 2:48 pm
Location: Reggio Emilia, Italy
Full Name: Lucio Mazzi

Re: Listing all VMs and associated backup jobs

Veeam Logoby Gav@GH » Wed Jul 25, 2012 12:38 am

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: Fri Jul 20, 2012 12:27 am

Re: Listing all VMs and associated backup jobs

Veeam Logoby Gav@GH » Sun Sep 09, 2012 7:46 am

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

viewtopic.php?f=26&t=13422
Gav@GH
Influencer
 
Posts: 21
Liked: 15 times
Joined: Fri Jul 20, 2012 12:27 am

Re: Listing all VMs and associated backup jobs

Veeam Logoby artecu » Wed Sep 12, 2012 8:07 am

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
artecu
Influencer
 
Posts: 23
Liked: 2 times
Joined: Fri Mar 23, 2012 6:52 am
Full Name: Andrew R Tilbury

Re: Listing all VMs and associated backup jobs

Veeam Logoby Gav@GH » Wed Sep 12, 2012 8:51 am 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.
Gav@GH
Influencer
 
Posts: 21
Liked: 15 times
Joined: Fri Jul 20, 2012 12:27 am

Re: Listing all VMs and associated backup jobs

Veeam Logoby artecu » Thu Sep 13, 2012 1:14 am

Thanks Again. All good now.
artecu
Influencer
 
Posts: 23
Liked: 2 times
Joined: Fri Mar 23, 2012 6:52 am
Full Name: Andrew R Tilbury


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests