-
- Enthusiast
- Posts: 39
- Liked: 4 times
- Joined: Aug 20, 2014 1:00 pm
- Contact:
Scripting the - Run script before and after the job
I have a Powershell script to create my replication jobs and want to run another powershell script before and after the job is run. I can manually edit the jobs and select the option and provide the path the scripts.
I would rather add the commands to select the run before and after scripts (and provide the path) to my initial script instead of manually editing each job . Is that a possible option to script in Powershell? I could not find any examples.
I would rather add the commands to select the run before and after scripts (and provide the path) to my initial script instead of manually editing each job . Is that a possible option to script in Powershell? I could not find any examples.
-
- Product Manager
- Posts: 20405
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Scripting the - Run script before and after the job
You can modify the post job settings of given job, using this code:
Thanks.
Code: Select all
$Job = Get-VBRJob -name "Job Name"
$Options = $Job.GetOptions()
$Options.Options.RootNode.PostJobCommand.Enabled = "True"
$Options.Options.RootNode.PostJobCommand.CommandLine = "Your command"
$Job.SetOptions($Options)
-
- Enthusiast
- Posts: 39
- Liked: 4 times
- Joined: Aug 20, 2014 1:00 pm
- Contact:
Re: Scripting the - Run script before and after the job
Hi, I'm just getting to test this out.
I added the script below to my job creation script and it gave an error when trying to create the post job option. The errors were on the "enabled" and "command line" property
I added the script below to my job creation script and it gave an error when trying to create the post job option. The errors were on the "enabled" and "command line" property
Code: Select all
[b]Script[/b]
#Set Pre Job Options to convert templates to virtual machines
$Job = Get-VBRJob -name $CreateJobName
$Options = $Job.GetOptions()
$Options.Options.RootNode.PostJobCommand.Enabled = "True"
$Options.Options.RootNode.PostJobCommand.CommandLine = "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe D:\Scripts\Templates\Working\TemplateRep2VM.ps1"
$Job.SetOptions($Options)
Code: Select all
[b]ERROR:[/b]
The property 'Enabled' cannot be found on this object. Verify that the property exists and can be set.
At D:\Scripts\Templates\Working\BuildTemplateCreate_vmrep_Job.ps1:371 char:2
+ $Options.Options.RootNode.PostJobCommand.Enabled = "True"
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
The property 'CommandLine' cannot be found on this object. Verify that the property exists and can be set.
At D:\Scripts\Templates\Working\BuildTemplateCreate_vmrep_Job.ps1:372 char:2
+ $Options.Options.RootNode.PostJobCommand.CommandLine = "C:\Windows\SysWOW64\Win ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (:) [], RuntimeException
+ FullyQualifiedErrorId : PropertyNotFound
-
- Product Manager
- Posts: 20405
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Scripting the - Run script before and after the job
What product version you're using? What is PS version?
-
- Enthusiast
- Posts: 39
- Liked: 4 times
- Joined: Aug 20, 2014 1:00 pm
- Contact:
Re: Scripting the - Run script before and after the job
Veeam Backup and Recovery v8 and PowerShell v4.0
-
- Enthusiast
- Posts: 39
- Liked: 4 times
- Joined: Aug 20, 2014 1:00 pm
- Contact:
Re: Scripting the - Run script before and after the job
I was able to get it working with the following:
$Options.JobScriptCommand.PostScriptEnabled = "true"
$Options.JobScriptCommand.PostScriptCommandLine = "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "my command"
thanks
$Options.JobScriptCommand.PostScriptEnabled = "true"
$Options.JobScriptCommand.PostScriptCommandLine = "C:\Windows\SysWOW64\WindowsPowerShell\v1.0\powershell.exe "my command"
thanks
-
- Product Manager
- Posts: 20405
- Liked: 2298 times
- Joined: Oct 26, 2012 3:28 pm
- Full Name: Vladimir Eremin
- Contact:
Re: Scripting the - Run script before and after the job
As far as I know, post job command can be configured in several ways: either through .rootnode or through .jobscriptcommand. Not sure why the former approach didn't work for you.
But I'm glad to hear that you've nailed it.
Thanks.
But I'm glad to hear that you've nailed it.
Thanks.
Who is online
Users browsing this forum: Majestic-12 [Bot] and 13 guests