You are viewing an old version of this page. View the current version.
Compare with Current
View Page History
Version 1
Next »
Scope
- The script adds an order to a job chain in a JobScheduler Master instance.
- PowerShell script is operational for command line execution with Windows, Linux, MacOS.
- The script is a wrapper that demonstrates use of the PowerShell CLI.
Script
Download
Usage
Syntax
Add-JobSchedulerOrder.ps1 [-JobChain] <String> [[-Order] <String>] [[-Parameters] <String>]
[[-At] <String>] [[-State] <String>] [[-EndState] <String>] [[-Id] <String>] [[-Url] <Uri>] [[-Credentials]
<PSCredential>] [[-Separator] <String>] [<CommonParameters>]
Help
- Windows
- Get Help Overview
pwsh.exe -c ./Add-JobSchedulerJob.ps1 -?
- Get Detailed Help
pwsh.exe -c Help ./Add-JobSchedulerOrder.ps1 -Detailed
- Linux, MacOS
- Get Help Overview
./Start-JobSchedulerOrder.ps1 -?
- Get Detailed Help
pwsh -C Help ./Add-JobSchedulerOrder.ps1 -Detailed
Functionality
- The script is executable from the command line
- for Windows by use of the
pwsh.exe
PowerShell interpreter like this:pwsh.exe -f ./Add-JobSchedulerOrder.ps1 -JobChain /bjb/shell_chain -Order sample_order
- for Linux, MacOS by directly calling the script and implictly using the shebang (
#!/usr/bin/pwsh
) to reference the interpreter like this:./Add-JobSchedulerOrder.ps1 -JobChain /bjb/shell_chain -Order sample_order
- Coding
#!/usr/bin/pwsh
param
(
[Parameter(Mandatory=$True,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $JobChain,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $Order,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[String] $Parameters = '',
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $At = 'now',
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $State,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $EndState,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $Id = $global:JobSchedulerId,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[Uri] $Url = $global:JobSchedulerUrl,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[PSCredential] $Credentials = $global:JobSchedulerCredentials,
[Parameter(Mandatory=$False,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
[string] $Separator = ';'
)
if ( !$Id )
{
throw "missing value for parameter -Id"
}
if ( !$Url )
{
throw "missing value for parameter -Url"
}
if ( !$Credentials -and !$Url.UserInfo )
{
throw "missing value for parameter -Credentials"
}
Import-Module JobScheduler
if ( $Url.UserInfo )
{
$ws = Use-JobSchedulerWebService -Url $Url -Id $Id
} else {
$ws = Use-JobSchedulerWebService -Url $Url -Id $Id -Credentials $Credentials
}
try
{
$order = Add-JobSchedulerOrder -JobChain $JobChain -Order $Order -At $At -State $State -EndState $EndState -Parameters ( ConvertFrom-StringData -StringData $Parameters.Replace($Separator, "`n") )
} catch {
throw $_.Exception
} finally {
$ws = Use-JobSchedulerWebService -Url $Url -Id $Id -Disconnect
}
Examples