PowerShell script exchange
Post Reply
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Add and Remove VMs from app group via PS

Post by ThomasMc »

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?
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Add and Remove VMs from app group via PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

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.
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Add and Remove VMs from app group via PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

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
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

Only thing I can see is if I delete the App Group and SB Job and then recreate them both
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Add and Remove VMs from app group via PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

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
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

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)
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Add and Remove VMs from app group via PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

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'.
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Add and Remove VMs from app group via PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

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
Sethbartlett
Veteran
Posts: 282
Liked: 26 times
Joined: Nov 10, 2010 6:51 pm
Full Name: Seth Bartlett
Contact:

Re: Add and Remove VMs from app group via PS

Post by Sethbartlett »

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.
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

Awesome, thanks Seth :D
ThomasMc
Veteran
Posts: 293
Liked: 19 times
Joined: Apr 13, 2011 12:45 pm
Full Name: Thomas McConnell
Contact:

Re: Add and Remove VMs from app group via PS

Post by ThomasMc »

Thanks again Seth, just thought I would add that if your using the above in a script then use

Code: Select all

$newjob.EnableScheduler()
at the end, for some reason when my script is doing the bizz it puts the job in a disabled state
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 21 guests