Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

Scope

  • The script starts an existing job in a JobScheduler Master instance.
  • PowerShell script is operational for command line execution with Windows, Linux, MacOS.
  • The script is a wrapper that demonstrates usage of the JobScheduler PowerShell CLI.

Script

Download

Usage

Syntax

Start-JobSchedulerJob.ps1 [-Job] <String> [[-Parameters] <String>] [[-At] <String>] [[-Id] <String>] [[-Url] <Uri>] [[-Credentials] <PSCredential>] [[-Separator] <String>] [<CommonParameters>]

Help

To display help information execute the following commands:

  • Windows
    • Get Help Overview
      • pwsh.exe -c ./Start-JobSchedulerJob.ps1 -?
    • Get Detailed Help
      • pwsh.exe -c Help ./Start-JobSchedulerJob.ps1 -Detailed
  • Linux, MacOS
    • Get Help Overview
      • ./Start-JobSchedulerJob.ps1 -?
    • Get Detailed Help
      • pwsh -c Help ./Start-JobSchedulerJob.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 ./Start-JobSchedulerJob.ps1 -Job /bjb/shell_job1
    • for Linux and MacOS by directly calling the script and by implictly using the shebang (#!/usr/bin/pwsh) to reference the interpreter like this:
      • ./Start-JobSchedulerJob.ps1 -Job /bjb/shell_job1
  • Use of JobScheduler PowerShelll CLI
    • Code

      Code Block
      languagepowershell
      titleStart-JobSchedulerJob.ps1
      collapsetrue
      #!/usr/bin/pwsh
       
      param
      (
          [Parameter(Mandatory=$True,ValueFromPipeline=$False,ValueFromPipelinebyPropertyName=$True)]
          [string] $Job,
          [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] $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
      {
          $job = Start-JobSchedulerJob -Job $Job -At $At -Parameters ( ConvertFrom-StringData -StringData $Parameters.Replace($Separator, "`n") )
      } catch {
          throw $_.Exception
      } finally {
          $ws = Use-JobSchedulerWebService -Url $Url -Id $Id -Disconnect
      }
    • Explanations
      • Basically the script is about the following operations:
        • Import the JobScheduler Module
        • Connect to the JOC Cockpit REST Web Service
        • Start an job with the JobScheduler Master
        • Disconnect from the JOC Cockpit REST Web Service
      • Follow above instructions about getting help to see detailed information about parameters

Examples

To display examples execute the following commands:

  • Windows
    • Get Examples
      • pwsh.exe -c Help ./Start-JobSchedulerJob.ps1 -Examples
  • Linux, MacOS
    • Get Examples
      • pwsh -c Help ./Start-JobSchedulerJob.ps1 -Examples