Inside Activate
...
PowerShell
PowerShell Scripting Introduction
6 min
powershell scripting introduction activate scripts can be written in c#, vb net or powershell this article outlines the differences and things to be aware of when implementing a powershell script see "the general scripting guidelines" below for more general information on activate scripts you can change the scripting language at the top of the script window in activate administrator warning powershell scripts that are designed to work interactively on the command line will generally need altering to work successfully in an activate environment this article is intended for users with a good understanding of activate and powershell this assumes that the associated activate service or task has already been designed and implemented and we are wanting to use powershell to complete the provisioning steps powershell limitations powershell scripts can generally perform all the functions available with c# or vb net however, powershell requires the creation of a seperate execution environment to execute the script this has a performance hit (memory and processor) for every powershell script that is run high performance services or tasks should not use powershell native activate functions are perferred over powershell for example, starting a powershell script to simply add a user to a group is 10 times slower that using the native functions powershell integration when a powershell script is executed, activate automtically adds a number of global variables that the script can use to access the activate environment these are true left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type left unhandled content type powershell commandline scripts powershell scripts that are designed to work interactively on the command line will generally need altering to work successfully in an activate environment as a script for a task the following changes will generally be required arguments for the script are generally read from $job arguments instead of the command line any user input required will need to be changed to operate non interactively write output or other output functions will need to be changed to $job logtrace or $job logaudit if required logging should be carefully reviewed to prevent performance or database size issues scripts designed for human interaction often perform a significant amount of logging that is not required the result of the script can be output back into the $job arguments or logged review any loops and long processes to prevent performance issues on your activate environment the following is a very simple example of adding a user to a group using powershell within activate mailto #@ps #available variables $job, $evaluator, $this, $organisation, $currentuser, $system $user = $job arguments getobject("user") $group = $job arguments getobject("group") $job logaudit("user = " + $user name) $group add($user) service scripts starting with activate v6 2 it is also now possible to write service customscripts as powershell scripts the following is an example and an outline for this script mailto #@ps #available variables $job, $evaluator, $this, $organisation, $currentuser, $system function create { param($srv) $job logaudit("ps create service instance " + $srv service name); } function delete { param($srv) $job logaudit("ps delete service instance " + $srv name); } function update { param($srv, $flags) }