PowerShell script exchange
Post Reply
rgeiser
Lurker
Posts: 2
Liked: never
Joined: May 24, 2011 12:59 pm
Full Name: Roland Geiser
Contact:

multiple vms with same name: how to delete from backup job?

Post by rgeiser »

We have an environment with hyper-v-clusters and scvmm. Let's assume we have several tenants with vms having exactly the same name. For example tenant1 has a "dc01", tenant2 has a vm "dc01" as well, etc. With Hyper-V and scvmm, this is possible.

Okay, lets assume we have multiple vms with the name "dc01" in the same backup-job. The vm objects are directly attached to the backup job. So we can see multiple "dc01" entries when reviewing the job.

Now customer "tenant1" is deleting his vm, it disappears in vmm. With a powershell script, we would like to delete this vm from the veeam backup job. How can we accomplish this, that only this tenant1-dc01 is deleted and not every vm with the same name? We couldn't find a way to pass the unique ID to the CMDlet remove-VBRJobObject.

For example, we tried this:

Code: Select all


# Find the vms with name dc01 (in this example, there are two):

PS C:\Windows\system32> Find-VBRHvEntity -Name dc01


ConnHost        : Veeam.Backup.Core.CHvDbScvmm
Type            : Vm
Reference       : b4314365-1aa7-4511-8242-b6b083ccf354
Id              : 33321d5b-0e15-4122-85ec-7065ef2ee005_b4314365-1aa7-4511-8242-b6b083ccf354
Name            : dc01
Path            : vs9000100.zmsmgtlab.com\All Hosts\DC GLATTBRUGG\LAB\CLUSTERS\VV9000110.zmsmgtlab.com\dc01
VmHostName      : VV9000110.zmsmgtlab.com
PowerState      : PoweredOn
ProvisionedSize : 0
UsedSize        : 0
GuestInfo       : Veeam.Backup.Model.CGuestInfo
ConnHostId      : 33321d5b-0e15-4122-85ec-7065ef2ee005
Platform        : EHyperV

ConnHost        : Veeam.Backup.Core.CHvDbScvmm
Type            : Vm
Reference       : fe92db84-ea96-4c08-87dc-ba743a8b9b85
Id              : 33321d5b-0e15-4122-85ec-7065ef2ee005_fe92db84-ea96-4c08-87dc-ba743a8b9b85
Name            : dc01
Path            : vs9000100.zmsmgtlab.com\All Hosts\DC GLATTBRUGG\LAB\CLUSTERS\VV9000110.zmsmgtlab.com\dc01
VmHostName      : VV9000110.zmsmgtlab.com
PowerState      : PoweredOn
ProvisionedSize : 0
UsedSize        : 0
GuestInfo       : Veeam.Backup.Model.CGuestInfo
ConnHostId      : 33321d5b-0e15-4122-85ec-7065ef2ee005
Platform        : EHyperV

# I choose one of them with it's ID to make it unique and put it in a variable:

PS C:\Windows\system32> $VMsObj = Find-VBRHvEntity -Name dc01 | Where-Object{$_.id -eq "33321d5b-0e15-4122-85ec-7065ef2ee005_b4314365-1aa7-4511-8242-b6b083ccf354"}

# Now I have one single object:

PS C:\Windows\system32> $VMsObj


ConnHost        : Veeam.Backup.Core.CHvDbScvmm
Type            : Vm
Reference       : b4314365-1aa7-4511-8242-b6b083ccf354
Id              : 33321d5b-0e15-4122-85ec-7065ef2ee005_b4314365-1aa7-4511-8242-b6b083ccf354
Name            : dc01
Path            : vs9000100.zmsmgtlab.com\All Hosts\DC GLATTBRUGG\LAB\CLUSTERS\VV9000110.zmsmgtlab.com\dc01
VmHostName      : VV9000110.zmsmgtlab.com
PowerState      : PoweredOn
ProvisionedSize : 0
UsedSize        : 0
GuestInfo       : Veeam.Backup.Model.CGuestInfo
ConnHostId      : 33321d5b-0e15-4122-85ec-7065ef2ee005
Platform        : EHyperV

# Now let's pass it to remove-vbrjobobject. Nothing happens, no vm is deleted from the job after this command:

PS C:\Windows\system32> Get-VBRJob -Name "dummy_job" | Get-VBRJobObject -Name $VMsObj  | Remove-VBRJobObject

# When I pass the name property of $VMsObj to remove-VBRJobObject, BOTH vms are deleted from the job.  

PS C:\Windows\system32> Get-VBRJob -Name "dummy_job" | Get-VBRJobObject -Name $VMsObj.Name  | Remove-VBRJobObject



Best regards
Roland
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by veremin »

I don't HV environment at hand but I think you can run the following script to determine where objects with the same name are located (host) and then delete the unneeded one.

Code: Select all

(Get-VBRJob -Name "Name of the job") | Get-VBRJobObject | select name, location 
Thanks.
rgeiser
Lurker
Posts: 2
Liked: never
Joined: May 24, 2011 12:59 pm
Full Name: Roland Geiser
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by rgeiser »

Thanks four your answer.

Yes but how to delete only one single object?

First, I choose the vm to delete on the basis of its ID. (remember, there are many vms with the name "dc01" in the same backupjob. I want to filter out one certain vm:)

Code: Select all

$VMsObj = Find-VBRHvEntity -Name dc01 | Where-Object{$_.id -eq "33321d5b-0e15-4122-85ec-7065ef2ee005_fe92db84-ea96-4c08-87dc-ba743a8b9b85"}
Now I want to pipe this one vm to remove-VBRJobObject:

Code: Select all

Get-VBRJob -Name "Dummy_Job" | Get-VBRJobObject -Name $VMsObj  | Remove-VBRJobObject -Completely
This above command has no effect. Nothing is deleted.

So I try it again with the name property of $VMSObj:

Code: Select all

Get-VBRJob -Name "Dummy_Job" | Get-VBRJobObject -Name $VMsObj.Name  | Remove-VBRJobObject -Completely
With this command all of the vms called dc01 are deleted in the backup job.

Is there a way to delete just my filtered vm? Working with the name seems not to work and I can't find a way to pass the (unique) ID to the remove-VBRJobObject CMDlet...

Best regards
Roland
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by veremin »

I was trying to propose different approach. Even though those VMs have the same name, they should be located on different hosts/clusters. Thus, it would be better to filter out VMs based on location parameter.

Something like:

Code: Select all

(Get-VBRJob -Name "Name of the job") | Get-VBRJobObject | where {$_.location -ne "My location"}
Thanks.
mwehrli
Lurker
Posts: 2
Liked: never
Joined: Feb 03, 2016 10:25 am
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by mwehrli »

This approach won't work for us. Its not unusual that multiple vms with the same name running on the same cluster. so we really need to identify a specific vm and delete it from a job. Another approach would be that we name the vm uniquely when we add it to a backup job (eq. dc_01-123456 --> 123456 would be a unique id), but it seems that it's not possible to set a specific for a vm when adding it into a backup job. the powershell cmdlet does not support that.

Best regards,
Marco
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by veremin »

Got it. So you know the Id of object that needs to be removed from the job. Then, you can write something like this:

Code: Select all

Get-VBRJob -Name "Name of backup job" | Get-VBRJobObject | Where {$_.GetObject().ObjectId -eq "Object Id"} | Remove-VBRJobObject -Completely
Object Id is the Reference property of entity that is returned by Find-VBRHvEntity cmdlet.

Thanks.
mwehrli
Lurker
Posts: 2
Liked: never
Joined: Feb 03, 2016 10:25 am
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by mwehrli »

Solved!! This one does exactly what we need. Is there going to be a more comfortable way to do this in a future version of Veeam? I'm just asking because without your help we had no chance to find out that there is a (hidden) VMM id.

Thanks a lot,
Marco
veremin
Product Manager
Posts: 20413
Liked: 2302 times
Joined: Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin
Contact:

Re: multiple vms with same name: how to delete from backup j

Post by veremin »

Is there going to be a more comfortable way to do this in a future version of Veeam?
I'm not sure about that, as your situation look like rather an isolated case, where VMs are almost identical with only VMM ID being different.

Typically, other parameters (that can be found easier) can be used as distinguishing factors.

Thanks.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot] and 13 guests