-
- Novice
- Posts: 4
- Liked: never
- Joined: Feb 10, 2015 8:36 pm
- Full Name: Paul Lansbergen
- Contact:
Toggle Enabled Jobs
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 }
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 }
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Toggle Enabled Jobs
I'm wondering what particular errors you're getting, as script looks OK at first glance.
-
- Novice
- Posts: 4
- Liked: never
- Joined: Feb 10, 2015 8:36 pm
- Full Name: Paul Lansbergen
- Contact:
Re: Toggle Enabled Jobs
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>
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>
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Toggle Enabled Jobs
Can you just input variables after "assigning" part, and see whether they contain something or not?
Thanks.
Code: Select all
$Week1Job = Get-VBRJob –Name “Joan USB Backup – Week 1“
$Week1Job
$Week2Job = Get-VBRJob –Name “Joan USB Backup – Week 2“
$Week2Job
-
- Novice
- Posts: 4
- Liked: never
- Joined: Feb 10, 2015 8:36 pm
- Full Name: Paul Lansbergen
- Contact:
Re: Toggle Enabled Jobs
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.
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.
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Toggle Enabled Jobs
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.
-
- Novice
- Posts: 4
- Liked: never
- Joined: Feb 10, 2015 8:36 pm
- Full Name: Paul Lansbergen
- Contact:
Re: Toggle Enabled Jobs
I ended up re-writing the script with different variable names and it worked with no problems. Everything else is the exact same.
-
- Product Manager
- Posts: 20400
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Toggle Enabled Jobs
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.
Who is online
Users browsing this forum: No registered users and 12 guests