Add and Remove VMs from app group via PS

PowerShell script exchange

Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Tue Nov 01, 2011 9:53 am

Having a little dig about to see if you could do this and are coming up with nothing, anyone know how to do this in powershell? or link the VSB job to another app group?
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby Sethbartlett » Tue Nov 01, 2011 12:59 pm

I am not seeing a way to add/remove VM's from an application group or even how to grab VMs out of an application group. I will have to do some digging...
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Tue Nov 01, 2011 1:12 pm

Cheer Seth, I thought I wasn't drilling in enough to get what I was looking for but like yourself couldn't find much from the current cmdlets. Funny thing is, the script that I'm doing is only missing this and a silly reset vcenter alarm to green to make it fully work.
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby Sethbartlett » Tue Nov 01, 2011 1:15 pm

You could always create a new application group on the fly and remove the old one and possibly add it back to the SureBackup job ;)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Tue Nov 01, 2011 1:21 pm

Sethbartlett wrote:You could always create a new application group on the fly and remove the old one and possibly add it back to the SureBackup job ;)



That was my original thinking but couldn't find how to change the SB Job App group or find its current App Group

1. Create New App Group with New vCenter Location
2. Edit vCenter SB Job changing Old App Group Name -> New App Group Name
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Tue Nov 01, 2011 2:04 pm

Only thing I can see is if I delete the App Group and SB Job and then recreate them both
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby Sethbartlett » Tue Nov 01, 2011 2:39 pm

What kind of script are you writing/what are you wanting to do? I might be able to help in another manner.
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Tue Nov 01, 2011 2:51 pm

It sort of goes like this

completed
1. vMotion vCenter VM
2. VM emigrating alarm triggers script
3. Waits for vMotion to complete
4. Find which host the VM was moved to
5. Update vCenter backup job

incomplete
6. update SB job somehow
7. Reset vCenter alarm to green and send report


What I've found is if the sb job is tied to the backup file it spins up 2 vCenter VMs on its next run(due to there being 2 of them in the file) and if its tied to the VI Host then it will be verifying the older backups
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Tue Nov 01, 2011 3:16 pm

This is what I have should I need to ditch App and SB

Code: Select all
$newhost = "ESXiHOST"
$appgroup = "vCenter App Group"
$vcvmname = "vcenter01.lab.local"
$vlab = "Virtual Lab 1"
$sbjobname = "Verify vCenter"

$fold = Get-VSBApplicationGroup | ?{$_.Name -eq $appgroup }

Remove-VSBApplicationGroup -AppGroup $fold -Confirm:$false

$newvsbserver = Get-VBRServer | ?{$_.Name -eq $newhost }
$newvsbobjt = Find-VBRObject -Server $newvsbserver | ?{$_.Name -eq $vcvmname }
Add-VSBApplicationGroup -Name $appgroup -Vm $newvsbobjt -Server $newvsbserver


$findvlab = Get-VSBVirtualLab | ?{$_.Name -eq $vlab }
$gnappgroup = Get-VSBApplicationGroup | ?{$_.Name -eq $appgroup }

Add-VSBJob -Name $sbjobname -VirtualLab $findvlab -AppGroup $gnappgroup


The Remove-VSBApplicationGroup seems to remove the App Group AND SB Job when ran(not sure if that by design or not but I can use to my advantage)
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby Sethbartlett » Tue Nov 01, 2011 5:23 pm

That would work. Seems pretty crazy but does work :P
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Sat Nov 05, 2011 7:01 pm

Wondering if you could help me out with this last bit, I'm trying to change the "Run Manually" from true to false, so far I've tried;

Code: Select all
$sbjob = Get-VSBJob | ?{$_.Name -eq "Verify vCenter"}
$sbjobopt = $sbjob.GetOptions()

$sbjobopt.RunManually = $false
"RunManually" is a ReadOnly property.

Set-VSBJobOptions -Job $sbjob -RunManually $false
Set-VSBJobOptions : A parameter cannot be found that matches parameter name 'RunManually'.
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby Sethbartlett » Mon Nov 07, 2011 1:33 pm

I'm not even sure of a Run Manually setting in the GUI. Why not just do:

Code: Select all
Get-VSBJob | ?{$_.name -eq "My Job"} | Start-VSBJob
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Mon Nov 07, 2011 3:32 pm

It controls this checkbox in the GUI

Image

What I'm doing is
Reading the old Schedule info
Destroy old app group and job
Create new app group and job
update job with old schedule
enable schedule **


Suppose I could just run it from windows tasks if I can't get that to change
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Re: Add and Remove VMs from app group via PS

Veeam Logoby Sethbartlett » Mon Nov 07, 2011 4:56 pm

Here is what you would want to do:

Code: Select all
$OldJob = Get-VSBJob | ?{$_.name -eq "Old Sb Job" }
$Schedule = $OldJob.GetScheduleOptions()
# Delete job, create new job
$NewJob = Get-VSBJob | ?{$_.name -eq "New Job"}
$NewJob.SetScheduleOptions($Schedule)


This should give you all your scheduling information. Which you probably know this part. The other part you will want to do is this:

Code: Select all
$opt = $OldJob.GetOptions()
$NewOptions = New-Object Veeam.Backup.Model.CDRJobOptions -ArgumentList ($true, $opt.ShutdownTestVms, $opt.EmailNotification, $opt.EmailNotificationAddresses, $opt.SnmpNotification, $opt.LinkWithJobs, $opt.RunningVmsNumber)
$NewJob.SetOptions($NewOptions)


I am our unsupported powershell guy, but this will do exactly what you need. The constructor for Options looks like this:

Code: Select all
public CDRJobOptions(bool runManually, bool shutdownTestVms, bool emailNotification, string emailNotificationAddresses, bool snmpNotification, bool linkWithJobs, int runningVmsNumber)
Skype: Sethbartlett88 - Make sure to label who you are and why you want to add me ;)
Twitter: @sethbartlett
If my post was helpful, please like it. Sometimes twitter is quicker to hit me up if you need me.
Sethbartlett
Expert
 
Posts: 282
Liked: 25 times
Joined: Wed Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett

Re: Add and Remove VMs from app group via PS

Veeam Logoby ThomasMc » Mon Nov 07, 2011 5:45 pm

Awesome, thanks Seth :D
ThomasMc
Expert
 
Posts: 293
Liked: 17 times
Joined: Wed Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell

Next

Return to PowerShell



Who is online

Users browsing this forum: No registered users and 8 guests