-
- Influencer
- Posts: 13
- Liked: never
- Joined: Nov 28, 2013 10:40 am
- Full Name: Asif Malik
- Contact:
Enable a Disabled Backup Job
Hi Guys,
Im trying to automate SRM, and need to enable a disabled veeam job after the SRM job becomes live.
Can this be done with powershell?
The job name can remain static for this example call it 'SRMBackup'
Im trying to automate SRM, and need to enable a disabled veeam job after the SRM job becomes live.
Can this be done with powershell?
The job name can remain static for this example call it 'SRMBackup'
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
You should use the following script:
Thanks.
Code: Select all
$Job = Get-VBRJob -name "Name of your Job"
$Job.EnableScheduler()
-
- Influencer
- Posts: 13
- Liked: never
- Joined: Nov 28, 2013 10:40 am
- Full Name: Asif Malik
- Contact:
Re: Enable a Disabled Backup Job
Thanks for the speedy response!
-
- Veeam Software
- Posts: 1818
- Liked: 655 times
- Joined: Mar 02, 2012 1:40 pm
- Full Name: Timothy Dewin
- Contact:
Re: Enable a Disabled Backup Job
If you want a one liner
or to disable all jobs
Code: Select all
Get-VBRjob -name "Name of your Job" | Disable-VBRJob
Code: Select all
Get-VBRjob | ? { $_.JobType -eq "Backup" } | Disable-VBRJob
-
- Service Provider
- Posts: 880
- Liked: 164 times
- Joined: Aug 26, 2013 7:46 am
- Full Name: Bastiaan van Haastrecht
- Location: The Netherlands
- Contact:
Re: Enable a Disabled Backup Job
Hi, I would like to add some errorhandling on the disable-enable process. What posible errors may occour?
Or is there an other/better method to check if the job has been disabled/enabled?
Code: Select all
Disable-VBRJob -Job "Jobname" -ErrorAction SilentlyContinue
If(!$?) {
#Something went wrong
}else{
#Succes
}
======================================================
Veeam ProPartner, Service Provider and a proud Veeam Legend
Veeam ProPartner, Service Provider and a proud Veeam Legend
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
I can't think of any issues that prevent you from disabling job.What posible errors may occour?
You can check whether or not given job is disabled via the following script:Or is there an other/better method to check if the job has been disabled/enabled?
Code: Select all
$Job = Get-VBRJob -name "Name of your Backup Job"
$Job.CanRunByScheduler() #True - enabled, #False - disabled
-
- Veeam Software
- Posts: 649
- Liked: 170 times
- Joined: Dec 10, 2012 8:44 am
- Full Name: Nikita Efes
- Contact:
Re: Enable a Disabled Backup Job
If you want to handle any error, you can log $_.Error in "Something went wrong" section to troubleshoot problems.
For example, it will catch the case when you don't have job with name "Jobname"
For example, it will catch the case when you don't have job with name "Jobname"
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Is there a way to have the script disable the job if it's enabled and enable the job if it's disabled? Would save having loads of scripts and scheduled tasks.
Also will this work for replication jobs as well as backup jobs?
Thanks
Also will this work for replication jobs as well as backup jobs?
Thanks
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
As mentioned above, the CanRunByScheduler() parameter returns $False when either the job is disabled or the job schedule isn't enabled ("Run the automatically checkbox" is unticked). So, the required scripts should be as the following:
The given scripts work with all type of jobs, except for tape ones.
Thanks.
Code: Select all
(Get-VBRJob | where {$_.CanRunByScheduler() -eq $False}).EnableScheduler() #enable disabled jobs
Code: Select all
(Get-VBRJob | where {$_.CanRunByScheduler() -eq $True}).DisableScheduler() #disable enabled jobs
Thanks.
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Thanks, can they be tweaked to only do it for my jobs called "Backup Job - 1" and "Replication Job - 1" ?
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
Try these scripts, then:
Thanks.
Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job 1"
If ($BackupJob.CanRunByScheduler() -eq $False) {$BackupJob.EnableScheduler()}
Else {$BackupJob.DisableScheduler()}
Code: Select all
$ReplicaJob = Get-VBRJob -name "Replication Job 1"
If ($ReplicaJob.CanRunByScheduler() -eq $False) {$ReplicaJob.EnableScheduler()}
Else {$ReplicaJob.DisableScheduler()}
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Getting these errors with this...v.Eremin wrote:Try these scripts, then:
Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job 1" If ($BackupJob.CanRunByScheduler() -eq $False) {$BackupJob.EnableScheduler()} Else {$BackupJob.DisableScheduler()}
Thanks.Code: Select all
$ReplicaJob = Get-VBRJob -name "Replication Job 1" If ($ReplicaJob.CanRunByScheduler() -eq $False) {$ReplicaJob.EnableScheduler()} Else {$ReplicaJob.DisableScheduler()}
Code: Select all
Method invocation failed because [Veeam.Backup.Core.CBackupJob] doesn't contain
a method named 'CanRunByScheduler'.
At C:\Scripts\EnableOrDisableMIJobs.ps1:4 char:33
+ If ($BackupJob.CanRunByScheduler <<<< () -eq $False) {$BackupJob.EnableSchedu
ler()}
+ CategoryInfo : InvalidOperation: (CanRunByScheduler:String) [],
RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Method invocation failed because [Veeam.Backup.Core.CBackupJob] doesn't contain
a method named 'CanRunByScheduler'.
At C:\Scripts\EnableOrDisableMIJobs.ps1:8 char:34
+ If ($ReplicaJob.CanRunByScheduler <<<< () -eq $False) {$ReplicaJob.EnableSche
duler()}
+ CategoryInfo : InvalidOperation: (CanRunByScheduler:String) [],
RuntimeException
+ FullyQualifiedErrorId : MethodNotFound
Thanks
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
What product version you're currently at?Getting these errors with this...
No, the abovementioned scripts should enable/disable the given jobs.Is this meant to tick/untick the "Run the job automatically" box under schedule?
Thanks.
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
7.0.0.771
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
May be the $BackupJob variable returns multiple entities, instead of one? Can you check whether the given variable is assigned properly? You can do it by inputting the variable in the pipeline:
Thanks.
Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job 1"
$BackupJob
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Yes those commands work?
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
The point was to test the way the variable is assigned. Whether it contains only one job, or multiple ones? So, what is shown in the pipeline if you run the said commands? One jobs or multiple ones? Also, you can try the Get-Member commandlet and see whether the given variable has "CanRunByScheduler()" method.
Thanks.
Thanks.
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Ok well this is the output...
Not sure what exactly to input to do this "Get-Member commandlet and see whether the given variable has "CanRunByScheduler()" method" ?
Code: Select all
PS C:\Scripts> $BackupJob = Get-VBRJob -name "Backup Job - MI"
PS C:\Scripts> $BackupJob
Job Name Type State Last Result Description
-------- ---- ----- ----------- -----------
Backup Job - MI VMware Backup Stopped Failed
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
Get-Member commandlet lists the parameter and properties the given object has. So, you can run the following script and see whether CanRunByScheduler() method is among those listed:
Thanks.
Code: Select all
$BackupJob = Get-VBRJob -name "Backup Job - MI"
$BackupJob | Get-Member
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Doesn't appear so but could these be used...?
DisableScheduler Method System.Void DisableScheduler()
EnableScheduler Method System.Void EnableScheduler()
DisableScheduler Method System.Void DisableScheduler()
EnableScheduler Method System.Void EnableScheduler()
Code: Select all
PS C:\Scripts> $BackupJob = Get-VBRJob -name "Backup Job - MI"
PS C:\Scripts> $BackupJob | Get-Member
TypeName: Veeam.Backup.Core.CBackupJob
Name MemberType Definition
---- ---------- ----------
Delete Method System.Void Delete()
DisableScheduler Method System.Void DisableScheduler()
EnableScheduler Method System.Void EnableScheduler()
Equals Method bool Equals(System.Object obj)
FindInitialRepository Method Veeam.Backup.Core.CBackupRepository ...
FindLastSession Method Veeam.Backup.Core.CBackupSession Fin...
FindSourceWanAccelerator Method Veeam.Backup.Core.CWanAccelerator Fi...
FindTargetRepository Method Veeam.Backup.Core.CBackupRepository ...
FindTargetWanAccelerator Method Veeam.Backup.Core.CWanAccelerator Fi...
GetDiskEffectiveCompression Method int GetDiskEffectiveCompression()
GetFilesEffectiveCompression Method int GetFilesEffectiveCompression()
GetHashCode Method int GetHashCode()
GetHvOijs Method Veeam.Backup.Core.HyperV.CHvOij[] Ge...
GetInitialRepository Method Veeam.Backup.Core.CBackupRepository ...
GetLastResult Method Veeam.Backup.Model.CBaseSessionInfo+...
GetLastState Method Veeam.Backup.Model.CBaseSessionInfo+...
GetObjectsInJob Method Veeam.Backup.Core.CObjectInJob[] Get...
GetOptions Method Veeam.Backup.Model.CJobOptions GetOp...
GetProxy Method System.Collections.Generic.IEnumerab...
GetScheduleOptions Method Veeam.Backup.Model.ScheduleOptions G...
GetSourceOffHostHvProxies Method Veeam.Backup.Core.CHvProxy[] GetSour...
GetSourceViProxies Method Veeam.Backup.Core.CViProxy[] GetSour...
GetSourceWanAccelerator Method Veeam.Backup.Core.CWanAccelerator Ge...
GetTargetHost Method Veeam.Backup.Core.CHost GetTargetHost()
GetTargetOffhostHvProxies Method Veeam.Backup.Core.CHvProxy[] GetTarg...
GetTargetProxies Method System.Collections.Generic.IEnumerab...
GetTargetRepository Method Veeam.Backup.Core.CBackupRepository ...
GetTargetViProxies Method Veeam.Backup.Core.CViProxy[] GetTarg...
GetTargetWanAccelerator Method Veeam.Backup.Core.CWanAccelerator Ge...
GetType Method type GetType()
GetVcdOijs Method Veeam.Backup.Core.CObjectInJob[] Get...
GetViOijs Method Veeam.Backup.Core.CObjectInJob[] Get...
GetVssOptions Method Veeam.Backup.Model.CVssOptions GetVs...
IsFileCopy Method bool IsFileCopy()
IsInBackupWindow Method bool IsInBackupWindow(System.DateTim...
IsStopped Method bool IsStopped()
IsWanAcceleratorEnabled Method bool IsWanAcceleratorEnabled()
LogHvProxySettings Method System.Void LogHvProxySettings()
LogJobOptions Method System.Void LogJobOptions(Veeam.Back...
LogJobSession Method System.Void LogJobSession(Veeam.Back...
Reload Method System.Void Reload()
ResetScheduleDependentJobs Method System.Void ResetScheduleDependentJo...
SetLatestRecheck Method System.Void SetLatestRecheck(System....
SetOptions Method System.Void SetOptions(Veeam.Backup....
SetScheduleDependentJobs Method System.Void SetScheduleDependentJobs...
SetVssOptions Method System.Void SetVssOptions(Veeam.Back...
SureMoveObj Method System.Void SureMoveObj(System.Guid ...
SureObjAdded Method System.Void SureObjAdded(System.Guid...
ToString Method string ToString()
-
- Product Manager
- Posts: 20415
- Liked: 2302 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Enable a Disabled Backup Job
As mentioned above, these methods are responsible for disabling/enabling job, not for providing information about schedule, in general. However, there is a property called .IsScheduleEnabled that can be used as a substitute for .CanRunBySheduler() method ; so, you might try and see whether it's present in your PS or not.
Thanks.
Thanks.
-
- VP, Product Management
- Posts: 6035
- Liked: 2860 times
- Joined: Jun 05, 2009 12:57 pm
- Full Name: Tom Sightler
- Contact:
Re: Enable a Disabled Backup Job
When scripts fail to run due to missing parameters/methods that really should exist I've generally found this to be caused by an outdated Powershell version, especially common on Windows 2008/2008R2 systems. If you haven't already done so I'd strongly suggest upgrading to at least Powershell 3.0, available at the following link:
http://www.microsoft.com/en-us/download ... x?id=34595
http://www.microsoft.com/en-us/download ... x?id=34595
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
Ah I see, I'll try this. Thankstsightler wrote:When scripts fail to run due to missing parameters/methods that really should exist I've generally found this to be caused by an outdated Powershell version, especially common on Windows 2008/2008R2 systems. If you haven't already done so I'd strongly suggest upgrading to at least Powershell 3.0, available at the following link:
http://www.microsoft.com/en-us/download ... x?id=34595
-
- Enthusiast
- Posts: 88
- Liked: 2 times
- Joined: Jul 31, 2013 12:05 pm
- Full Name: Si
- Contact:
Re: Enable a Disabled Backup Job
That fixed it! Thankstsightler wrote:When scripts fail to run due to missing parameters/methods that really should exist I've generally found this to be caused by an outdated Powershell version, especially common on Windows 2008/2008R2 systems. If you haven't already done so I'd strongly suggest upgrading to at least Powershell 3.0, available at the following link:
http://www.microsoft.com/en-us/download ... x?id=34595
Who is online
Users browsing this forum: Semrush [Bot] and 14 guests