Toggle Enabled Jobs

PowerShell script exchange

Toggle Enabled Jobs

Veeam Logoby Adon_Sune » Tue Feb 10, 2015 8:47 pm

I'm trying to write a powershell script that will toggle the enabled jobs once a week and run it from a scheduled task. I keep getting an error on the Enable/Disable commands in the if statement. I've triple checked the names of the jobs and they are correct. Is there something obvious I'm missing here?

Set-ExecutionPolicy RemoteSigned
Add-PSSnapin VeeamPSSnapin

$Week1Job = Get-VBRJob –Name “Joan USB Backup – Week 1“
$Week2Job = Get-VBRJob –Name “Joan USB Backup – Week 2“

If ($Week1Job.IsScheduleEnabled –eq $False) {
Enable-VBRJob -Job $Week1Job
Disable-VBRJob -Job $Week2Job }
Else {
Enable-VBRJob -Job $Week2Job
Disable-VBRJob -Job $Week1Job }
Adon_Sune
Novice
 
Posts: 4
Liked: never
Joined: Tue Feb 10, 2015 8:36 pm
Full Name: Paul Lansbergen

Re: Toggle Enabled Jobs

Veeam Logoby v.Eremin » Wed Feb 11, 2015 11:28 am

I'm wondering what particular errors you're getting, as script looks OK at first glance.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Toggle Enabled Jobs

Veeam Logoby Adon_Sune » Tue Feb 17, 2015 4:37 pm

PS C:\scripts> .\icorrswitch.ps1
Enable-VBRJob : Cannot validate argument on parameter 'Job'. The argument is null. Supply a non-null argument and try t
he command again.
At C:\scripts\ICORRSwitch.ps1:11 char:19
+ Enable-VBRJob -Job <<<< $Week2Job
+ CategoryInfo : InvalidData: (:) [Enable-VBRJob], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.EnableVBRJob

Disable-VBRJob : Cannot validate argument on parameter 'Job'. The argument is null. Supply a non-null argument and try
the command again.
At C:\scripts\ICORRSwitch.ps1:12 char:20
+ Disable-VBRJob -Job <<<< $Week1Job }
+ CategoryInfo : InvalidData: (:) [Disable-VBRJob], ParameterBindingValidationException
+ FullyQualifiedErrorId : ParameterArgumentValidationError,Veeam.Backup.PowerShell.Command.DisableVBRJob

PS C:\scripts>
Adon_Sune
Novice
 
Posts: 4
Liked: never
Joined: Tue Feb 10, 2015 8:36 pm
Full Name: Paul Lansbergen

Re: Toggle Enabled Jobs

Veeam Logoby v.Eremin » Wed Feb 18, 2015 10:05 am

Can you just input variables after "assigning" part, and see whether they contain something or not?

Code: Select all
$Week1Job = Get-VBRJob –Name “Joan USB Backup – Week 1“
$Week1Job
$Week2Job = Get-VBRJob –Name “Joan USB Backup – Week 2“
$Week2Job


Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Toggle Enabled Jobs

Veeam Logoby Adon_Sune » Wed Feb 18, 2015 7:29 pm

Updated the script to output the job name after assigning it to the variable. Comes back with a blank.
If I manually enter all the commands in the script one at a time from the powershell window it works fine. It just fails when run as a script.
Adon_Sune
Novice
 
Posts: 4
Liked: never
Joined: Tue Feb 10, 2015 8:36 pm
Full Name: Paul Lansbergen

Re: Toggle Enabled Jobs

Veeam Logoby v.Eremin » Thu Feb 19, 2015 12:04 pm

I see that in the beginning of the script you're setting execution policy to remote signed, are running the code against some remote machine? If so, does this machine have a backup server installed? Thanks.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin

Re: Toggle Enabled Jobs

Veeam Logoby Adon_Sune » Thu Feb 19, 2015 3:10 pm

I ended up re-writing the script with different variable names and it worked with no problems. Everything else is the exact same.
Adon_Sune
Novice
 
Posts: 4
Liked: never
Joined: Tue Feb 10, 2015 8:36 pm
Full Name: Paul Lansbergen

Re: Toggle Enabled Jobs

Veeam Logoby v.Eremin » Thu Feb 19, 2015 3:19 pm

Strange thing, indeed, since variable names should matter and you seem to have same in both parts of the script (assigning, enabling/disabling). Anyway, glad to hear that you're up and running now.
v.Eremin
Veeam Software
 
Posts: 13266
Liked: 968 times
Joined: Fri Oct 26, 2012 3:28 pm
Full Name: Vladimir Eremin


Return to PowerShell



Who is online

Users browsing this forum: No registered users and 7 guests