PowerShell script exchange
Post Reply
haroonh
Novice
Posts: 8
Liked: never
Joined: Mar 29, 2019 1:59 pm
Full Name: Haroon Hanif
Contact:

adding a tag to each VM in the Backup/Replica Job using powershell

Post by haroonh »

Hi,

I am assigned a job to assign tags to all the VMs backed up or replicated by Veeam and I need help in that please, I see there is an option of using script which you can run pre or post backup and I think that could be the option which is useful for assigning the tag to the VM or replacing the existing tag from "No Backup" to "Backup" after the backup is taken.

Tag name: Backup, category: Veeam.
Tag name: No Backup, category: Veeam.

We don't have tags on our existing VMs so rather than going through each VM and assigning the tag manually, I thought it would be easier to add tag using Veeam and will be able to report all the VMs not backed up by Veeam
if somebody has created a powershell script for something similar, could they please share it,

I really appreciate your time and effort on this.

Kind Regards,
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: adding a tag to each VM in the Backup/Replica Job using powershell

Post by veremin » 1 person likes this post

Doesn't adding backup details to VM attribute solve your problem? Thanks!
haroonh
Novice
Posts: 8
Liked: never
Joined: Mar 29, 2019 1:59 pm
Full Name: Haroon Hanif
Contact:

Re: adding a tag to each VM in the Backup/Replica Job using powershell

Post by haroonh »

Thanks for replying,
What we plan to do is to use ansible to create and tag the new Virtual machines on the basis of whether it needs a backup or not. And As we already have jobs created for the replication and backups in veeam , by running the post backup/replication script we will be able to tag the VMs already in the back up and then can filter any VMs which should be backed up but are not in veeam jobs based on their tags.

Further down the line we are thinking of adding the new VMs dynamically into the veeam jobs.
Thats why I was looking for the script.
Could you please advise if you think adding the attribute will be better.
I hope this makes sense.
haroonh
Novice
Posts: 8
Liked: never
Joined: Mar 29, 2019 1:59 pm
Full Name: Haroon Hanif
Contact:

Re: adding a tag to each VM in the Backup/Replica Job using powershell

Post by haroonh »

I have tried the following script which pulls the objects in the job, displays $Objects.name (VMs) properly on the screen but when I try to put $Objects.name in the CSV format, it gives me the length of the string rather than the VM names, script is as follows.

# Load Snap-ins

# Add Veeam snap-in if required
If ((Get-PSSnapin -Name VeeamPSSnapin -ErrorAction SilentlyContinue) -eq $null) {add-pssnapin VeeamPSSnapin}

Connect-VBRServer


$JobnName = "Replication Veeam_utility_test"
$JobObject = Get-VBRJob -name $JobnName
$Objects = $JobObject.GetObjectsInJob()
$Objects.name
$Objects.name | export-csv -Path c:\$JobnName.csv


if there is a way, I could retrieve them individually and then use them in a loop to apply the tag on them will be great and any help in that will be greatly appreciated
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: adding a tag to each VM in the Backup/Replica Job using powershell

Post by veremin »

Take a look at this report. It has section about VMs backed up within last X hours.

Take this logic and combine it with PowerCLI tag assignment cmdlet.

Thanks.
haroonh
Novice
Posts: 8
Liked: never
Joined: Mar 29, 2019 1:59 pm
Full Name: Haroon Hanif
Contact:

Re: adding a tag to each VM in the Backup/Replica Job using powershell

Post by haroonh »

Hi v.eremin,

Thanks for the Link, really appreciate your help.
veremin
Product Manager
Posts: 20283
Liked: 2257 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: adding a tag to each VM in the Backup/Replica Job using powershell

Post by veremin »

If I remember correctly, the script provides you with the list of VMs that have been backed up during the specified time interval, which means you will need to change the logic slightly, so that instead of VMs that have not been backed up you get VMs that have.

Then, you will need to convert this list from Veeam PS objects to VMware PowerCLI ones.

After that, assign tag to PowerCLI VM objects, using the referenced cmdlet.

Thanks!
Post Reply

Who is online

Users browsing this forum: No registered users and 11 guests