Info | ||||
---|---|---|---|---|
| ||||
|
Table of Contents | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
PowerShell Scripting
PowerShell is the Scripting a scripting shell of the Windows world. A PowerShell script can be used in Jobs jobs as easy as other shell scripts.
An example:
Code Block |
---|
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/job.xml job ] <job title="Execute a PowerShell Script" order="yes" stop_on_error="no"> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]<script language="shell"><![CDATA[ echo SCHEDULER_DATA = %SCHEDULER_DATA% echo SCHEDULER_PARAM_SCRIPT_FILENAME = %SCHEDULER_PARAM_SCRIPT_FILENAME% powershell.exe get-ExecutionPolicy powershell.exe -nologo -NonInteractive -noprofile -file "%SCHEDULER_PARAM_SCRIPT_FILENAME%" "%SCHEDULER_PARAM_SCRIPT_FILENAME%" exit %errorlevel% ]]> </script> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/order.xml monitor ]<monitor name="configuration_monitor" ordering="0"> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/script.xml script ]<script java_class="sos.scheduler.managed.configuration.ConfigurationOrderMonitor" language="java"/> </monitor> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time]<run_time/> </job> |
This job is an order-driven job and therefore the parameters parameter for this job comes from an order like that one below:
Code Block |
---|
<[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/order.xml order ] <order title="Executes the File PowerShell-Hallo.ps1"> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/params.xml params]><params> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/param.xml param ]<param name="Script_Filename" value="$\{SCHEDULER_DATA\}\config\live\PowerShell\Powershell-Hallo.ps1"/> </params> <[http://www.sos-berlin.com/doc/en/scheduler.doc/xml/run_time.xml run_time] <run_time let_run="no"/> </order> |
Within the order the value of the parameter Script_Filename, which specify the name of the script to be executed, will be passed to the job as an environment variable.
The script, which is executed in the above example, is as much as simple:
Code Block |
---|
$A="Hello, PowerShell ..." $A Write-Host "Num Args:" $args.Length; foreach ($arg in $args) \{ Write-Host "Arg: $arg"; \} Write-Host "Environment-var Scheduler-Data is : $env:SCHEDULER_DATA" Write-Host "Operating system is : $env:OS" exit $lastexitcode # to change the policy for using powershell you can use this .adm file: # http://www.microsoft.com/download/en/confirmation.aspx?id=25119 |
The output in the log-file looks like the text below:
Code Block |
---|
C:\Program Files (x86)\scheduler>echo SCHEDULER_DATA = C:/Program Files (x86)/scheduler
SCHEDULER_DATA = C:/Program Files (x86)/scheduler
C:\Program Files (x86)\scheduler>echo SCHEDULER_PARAM_SCRIPT_FILENAME = C:/Program Files (x86)/scheduler\config\live\PowerShell\Powershell-Hallo.ps1
SCHEDULER_PARAM_SCRIPT_FILENAME = C:/Program Files (x86)/scheduler\config\live\PowerShell\Powershell-Hallo.ps1
C:\Program Files (x86)\scheduler>powershell get-ExecutionPolicy
SCHEDULER-918 state=release
RemoteSigned
C:\Program Files (x86)\scheduler>powershell -noprofile \
-file "C:/Program Files (x86)/scheduler\config\live\PowerShell\Powershell-Hallo.ps1" \
"C:/Program Files (x86)/scheduler\config\live\PowerShell\Powershell-Hallo.ps1"
Hello, PowerShell ...
Num Args: 1
Arg: C:/Program Files (x86)/scheduler\config\live\PowerShell\Powershell-Hallo.ps1
Environment-var Scheduler-Data is : C:/Program Files (x86)/scheduler
Operating system is : Windows_NT
C:\Program Files (x86)\scheduler>exit 0
|
see also:
...
Related Downloads
See also
- How to get the Exit exit code of a powershell PowerShell script
- How to pass variable-values parameters from JS JobScheduler to a powershell PowerShell script
- A How to configure a generic PowerShell Jobjob
- Passing Parameters to shell-jobs
- Passing parameters from shell-jobs to JS
- How to set parameters in shell scripts and make them accessible to the next node in a job chain
- Example for control of How to control the process flow of a jobchain job chain by exit codes