Pulling the Agent Image

'plus' images which include a recent PowerShell environment and the JS7 - PowerShell Module are available, for example:

Pulling the Plus Agent Image
docker image pull sosberlin/js7:agent-2-5-0-plus

Note: A current release should be applied as available from https://hub.docker.com/r/sosberlin/js7

Running the Agent Container from a 'plus' Image

Image names suffixed with "plus" include a recent PowerShell environment and the JS7 - PowerShell Module. This increases the image size and not all users might feel the need to use PowerShell. At the same time the JS7 PowerShell Module allows simplified use of the JS7 - REST Web Service API.

PowerShell Profile

By default the 'plus' Agent image creates the following PowerShell profile inside the container with the path /home/jobscheduler/.config/powershell/Microsoft.PowerShell_profile.ps1:

Default PowerShell profile
$PSReadLineOptions = @{Colors=@{"Default"="Blue"; "Command"="Blue"; "Parameter"="Blue"; "Variable"="Blue"; "Number"="Blue"; "Member"="Blue"; "Operator"="Blue"}}
Set-PSReadlineOption -Colors $PSReadLineOptions.Colors

if ( Test-Path $env:JS7_AGENT_CONFIG_DIR/Microsoft.PowerShell_profile.ps1 -PathType Leaf -ErrorAction SilentlyContinue )
{
  .  $env:JS7_AGENT_CONFIG_DIR/Microsoft.PowerShell_profile.ps1
}

Explanation:

  • Readline options specify colors used for better visibility of the prompt when directly invoking PowerShell inside a container.
  • A profile assumed inside the Agent's config directory is executed if applicable.

Running PowerShell Commands inside the Container

To try out a 'plus' Agent container you can use the following sequence of commands:

Execute PowerShell cmdlets in a "plus" container
# From the Docker host invoke a PowerShell session within the Agent container
docker exec -ti js7-agent-primary pwsh

# Receive a PowerShell prompt like this
#   PowerShell 7.1.3
#   Copyright (c) Microsoft Corporation.
#   https://aka.ms/powershell
#   Type 'help' to get help.
#   PS />

# Load the JS7 PowerShell module
PS />Import-Module JS7

# Connect to the JOC Cockpit container specifying account ("root") and password ("root") with the JOC Cockpit URL like this:
PS />Connect-JS7 -Url http://root:root@js7-joc-primary:4446 -Id jobscheduler

# An alternative way is to create a credential object like this
#   PS />$credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList "root", ( "root" | ConvertTo-SecureString -AsPlainText -Force) )
#   PS />Connect-JS7 -Url http://js7-joc-primary:4446 -Id jobscheduler -Credentials $credentials

# The recommended way is to login to the JOC Cockpit REST API by use of a certificate should JOC Cockpit be configured for HTTPS and certificate based authentication
#   PS />$credentials = ( New-Object -typename System.Management.Automation.PSCredential -ArgumentList "certs", ( "jobscheduler" | ConvertTo-SecureString -AsPlainText -Force) )
#   PS />Connect-JS7 -Url https://js7-joc-primary:4443 -id jobscheduler -KeyStorePath /var/sos-berlin.com/js7/agent/var_4445/config/private/https-keystore.p12 -KeyStoreCredentials $credentials -RootCertificatePath /var/sos-berlin.com/js7/agent/var_4445/config/private/https-truststore.p12 -RootCertificateCredentials $credentials

# Display Controller status
PS />Get-JS7ControllerStatus -display

# The command should return the following output:
#   ________________________________________________________________________
#   ....... Controller ID: jobscheduler
#   ............. version: 2.5.0
#   ................. URL: http://controller-2-2-primary:4444
#   ................ role: PRIMARY
#   ............... title: PRIMARY CONTROLLER
#   ....... running since: 04/20/2022 15:00:34
#   ...... security level: MEDIUM
#   ..... cluster coupled: True
#   .. cluster node state: active
#   .... component status: operational
#   ... connection status: established
#   ________________________________________________________________________

Running PowerShell Jobs

To execute PowerShell code from a job running inside a 'plus' Agent container you can use a sequence of commands for the job script such as:

Execute PowerShell jobs in a "plus" container
pwsh -NoLogo -NonInteractive -Command '& {
    Import-Module JS7
    Connect-JS7 -Url http://root:root@js7-joc-primary:4446 -Id jobscheduler

    Get-JS7ControllerStatus -display
}'