Powershell
Activities
Interactive PSscript
This activity runs a powershell script under interactive session.
Prequisites
Server Settings
- UAC disabled - User Account Control should be disabled (to allow the agent to start a process as a different user).
- Powershell Execution Policy Unrestricted - Before you use this activity, make sure the powershell Execution Policy is set to unrestricted for the Local Machine.
Local Security Policy
User whose active session ID will be used ,must be added to the following security privileges. In order to do this, log in to the remote server with a user with elevated privileges and go to Control Panel-> Administrative Tools -> Local Security Policy. When Local Security Policy opens, go to Local policies -> User Rights Assignment and add the desired user to the following:
- Act as part of the operating system
- Create a token object
- Log on as a batch job
- Replace a process level token
Local Users and Groups
User whose active session ID will be used, must be added to the local administrators group.
Activity Parameters
The Interactive PSscript activity parameters can be provided by manual inserted values or via IN arguments or variables:
Interactive Agent:
- ClientHash (text box editor type) (type: string): the client hash for the Rest API client app. It can be copied from Flowster Administrator by selecting the client app for the Rest API.
- Password (password editor type) (type: string): the password for the rest API username.
- Password Binding (text box editor type) (type: string): bind to a variable containing the encrypted password for connection.(This parameter is only used when the user wants to send an encrypted password from outside the task, for example Flowster Studio Portal execution.
- Session ID (text box editor type) (type: Int32): specify an active session ID returned by the 'Connect To Remote Desktop' activity or 'Get Remote Desktop Session' activity.If left empty, the first active session will be used.
- Timeout (text box editor type) (type: Int32): specify the number of minutes to wait for the operations in script to be completed.
- Username (text box editor type) (type: string): the security user for the Rest API configured in Flowster Administrator. E.g. 'domain\username'.
Parameters:
- Command (text box editor type) (type: string):
- the PowerShell inline script. This parameter takes precedence over the Script Code parameter. Without $using, a $a workflow variable (variable defined via workflow, visible in the Variables area) is not visible in the script. $Using imports the variable and its current value (e.g. {$a = $using:a+1; $a})
- the Command editor has a syntax highlighting toggle, for displaying the lines according to the chosen language. In the example below, PowerShell was used:
the user can also use an external editor of his/her choice via the button to the left of the edit field (). The external editor is by default Windows notepad, but it can be changed in the Designer Settings.
- Include Administrator Scripts (combobox editor type) (type: string): this parameter specifies whether to include the execution of the scripts assigned to the workflow in Administrator. The workflow selected from Administrator will be executed first and added to the result of the powershell script.
- Parameters collection (collection editor type) (type: string): the parameters you want to send with the request. e.g. Name: -ArgumentList and Value:arg1.
- Script Passwords (password collection editor type) (type: string): the names and the values for the password types variables which will be used in the script. These passwords will be incorporated in the script with the $using: syntax
- password value: this value should be manually configured in the editor window. The value will also be encrypted in thew workflow's content file
- password binding value: this field can be linked to an existing variable, argument or global variable, where the value would be automatically taken during the workflow's execution
- this is an example of a script which connects to a vCenter server using different credentials and including multiple passwords:
- Script Code (text box editor type) (type: string): the Powershell script code to be executed. For example: "mkdir 'C:\FlowsterSolutions'" (this command creates a folder with the specified path).
- Script File (text box editor type) (type: string): the Powershell script file. This parameter takes precedence over the Command and the Script Code parameter.
The Read Only Output variable are the possible output values that the activity will provide:
- Output (type: Boolean): outputs True whether the operation succeeded or False otherwise.
PSscript
This activity runs a powershell script.
Activity Parameters
The PSscript activity parameters can be provided by manual inserted values or via IN arguments or variables:
Parameters:
- Command (text box editor type) (type: string):
- the PowerShell inline script. This parameter takes precedence over the Script Code parameter. Without $using, a $a workflow variable (variable defined via workflow, visible in the Variables area) is not visible in the script. $Using imports the variable and its current value (e.g. {$a = $using:a+1; $a})
- the Command editor has a syntax highlighting toggle, for displaying the lines according to the chosen language. In the example below, PowerShell was used:
the user can also use an external editor of his/her choice via the button to the left of the edit field. The external editor is by default Windows notepad, but it can be changed in the Designer Settings.
- Include Administrator Scripts (combobox editor type) (type: string): this parameter specifies whether to include the execution of the scripts assigned to the workflow in Administrator. The workflow selected from Administrator will be executed first and added to the result of the powershell script.
- Parameters collection (collection editor type) (type: string): the parameters you want to send with the request. e.g. Name: -ArgumentList and Value:arg1.
- Run isolated (text box editor type) (type: string): specify whether to execute the script on a new isolated application domain. This parameter should be set to True when the script contains import modules
- Script Passwords (password collection editor type) (type: string): the names and the values for the password types variables which will be used in the script. These passwords will be incorporated in the script with the $using: syntax
- password value: this value should be manually configured in the editor window. The value will also be encrypted in thew workflow's content file
- password binding value: this field can be linked to an existing variable, argument or global variable, where the value would be automatically taken during the workflow's execution
- Script Code (text box editor type) (type: string): the Powershell script code to be executed. For example: "mkdir 'C:\FlowsterSolutions'" (this command creates a folder with the specified path).
- Script File (text box editor type) (type: string): the Powershell script file. This parameter takes precedence over the Command and the Script Code parameter.
- Script Parameters (text box editor type) (type: string): the parameters that will be passed to the PowerShell code stored in a PowerShell script file. For multiple parameters, separate the values with comma ( , ). This parameter will take effect only when a script file is selected for execution.
As mentioned above, the values for all the required parameters can be provided by IN arguments or variables. Below is an example of predefined arguments, ready to be used by the PS Script activity:
Parameters Remoting:
- Remote Machine (text box editor type): the name of the machine for the remote connection
- Remote Password (password box editor type) (type: string): the value for the user password that will be used in the script (encrypted).
- Remote Password Binding (text box editor type) (type: string): bind to a variable containing the encrypted password for the PS machine host.
- Remote User (text box editor type): the user name for the remote connection. The user name can be added with domain ( mydomain\username) or without it.
The Read Only Output variable are the possible output values that the activity will provide:
- Output (type: collection<PSObjects>): outputs a collection of "PSObjects" type objects.
- Output Error Messages (type: collection<string>): outputs a collection of strings containing the error messages from the powershell execution.
- Output Rows (type: int32): outputs the number of "PSObjects" type objects returned by the execution of the script.
Powershell Demo sequence:
On Execution (Home->(Execution section) Start button) - workflow "Powershell_Demo" , Tracking Data panel should display:
Get-Service command situation
The Get-Service commands requires the activity to use Runspaces or Jobs in order to properly execute, without throwing exceptions.
The most common error message is that there is no available Runspace to execute the current thread.
For preventing this situation, the command will be used as a Job, using ScriptBlock.
The PSScript code will look like:
Information regarding the retrieved services can be extracted from the PSScript's output and converted to ServiceController and ServiceControllerStatus objects:
- Service Display Name
- Service Machine Name
- Service Status
The variables should be declared with the following types:
Powershell Demo using a File Repository script with parameters:
To use arguments and variable in a script the following syntax needs to be used ${using:argument_name} or ${using:variable_name}
A script example can be:
In the powershell activity add in the Script code parameter the output from the GetFileRepositoryContent activity.
For using the parameter collection a script example can be:
Powershell DSC
This activity rsends the compiled configuration files(.mof) to the MS Configuration Service for execution
Activity Parameters
The Powershell DSC activity parameters can be provided by manual inserted values or via IN arguments or variables:
Parameters:
Computer Name (text box editor type) (type: string): enter the machine name for the remote connection
- Configuration file (browse to filer type) (type: string): this parameter specifies a file path of a folder that contains configuration setting files. This cmdlet publishes and applies these configuration settings to computers that have setting files in the specified path. Each target node must have a setting file of the following format: NetBIOS Name.mof
- Remote Password (password box editor type) (type: string): the value for the password that will be used for the remote connection.
- Remote Password Binding (text box editor type) (type: string): bind to a variable containing the encrypted password for the remote connection.
- Remote Username (text box editor type) (type: string): Enter the user name for the remote connection. Remote username is not requiered, if no username is added the activity will use the login users credentials.
The Read Only Output variable are the possible output values that the activity will provide:
- Output (type: Boolean): outputs whether the operation succeded or not.
PS Script External
This activity runs an external powershell script (allowing the user to pass on parameters directly via the activity and not by using arguments list).
Activity Parameters
The PS Script External activity parameters can be provided by manual inserted values or via IN arguments or variables:
Parameters:
Parameters Collection (collection editor type) (type: string): this parameter is populated with members' names mirroring the parameters' names in the selected powershell script (params() section), after the selection of the powershell script using Script file parameter (by default, this parameter is empty).
If parameters are added to the powershell script, in order to reflect the changes in the Parameters Collection parameter, the powershell script must be chosen again using the Script file parameter.
Note that only the members' names are populated in the Parameters Collection. Values must be added by the user. Type string and Int32 can be used as direct values, whereas for boolean and array type parameter, variables/arguments must be used.- Run isolated (text box editor type) (type: string): specify whether to execute the script on a new isolated application domain. This parameter should be set to True when the script contains import modules
- Script file (file browser type) (type: string): this parameter specifies a file path of a powershell script.
The Read Only Output variable are the possible output values that the activity will provide:
- Output (type: collection<PSObjects>): outputs a collection of 'PSObject' type objects.
- Output Rows (type: Int32): outputs the number of 'PSOBjects' type objects returned by the execution of the script.
Execution: