Script - Powershell
The Powershell Script workflow object is used to execute a Powershell script.
This workflow object runs silently, meaning it has no user interaction. Silent workflow object are displayed with this icon.
Security Alert
Powershell and SQL scripting has the potential to perform drastic system changes, unwanted, or even malicious effects. Use of these features should be carefully monitored and controlled via the appropriate application security roleUse
Write a powershell script in the workflow object (or call another script from this PS script).
Variables can also be used in the script. To insert a pre-defined variable, start typing double angular brackets "<<", and all of the available variables will be displayed in a pick-list. Choose the variable you want to inert its place-holder. It's value will be substituted for the place-holder when the script is run.
Use the Add Tag button to insert placeholder tags/tokens for the client, site, asset or job. These tags will be replaced with the unique database IDs of each entity type. These tags/tokens allow you to be specific in updates, or other SQL/Scripting actions.
Powershell scripting requires that the Windows Management Framework 4.0 is installed on the machine that is running the script. See https://learn.microsoft.com/en-us/powershell/scripting/windows-powershell/wmf/overview?view=powershell-7.3
Using workflow date variables in Powershell scripts
When using workflow date variables in a Powershell script, they are implemented as native Powershell dates. This means you can use Powershell date commands within the script against the date.
For example, the following script uses the Powershell “.AddHours” function to the date.
$Datetest = <<DateVariable>>
$Datetest = $Datetest.AddHours(3)
Write $Datetest
If you need to need to use the date within a string, you can use the following syntax to concatenate a string with the date variable.
$myJSON = "This is the first part " + (<<DateVariable>>) + " and some more text"
...or
$myJSON = "This is the first part $(<<DateVariable>>) and some more text"
Use the .ToString function to format a date into a specific format. This may be required for API calls, or general formatting within a string.
$myJSON = "This is the first part $(<<DateVariable>>.ToString('yyyy/MM/ddTHH:mm:00')) and some more text"
See the Powershell documentation for more examples. https://learn.microsoft.com/en-us/powershell/
Example calling the HelpMaster WebAPI to update a control set
This example uses PowerShell to make a http call to the HelpMaster web api to call the UpdateControlSetValue_String method.
# Get a user token
$uri = 'https://webapi.wizbangwidgets.com/User/GetToken'
$body = '{ "apiKey": "59867a71-a601-43cd-9fc2-2eed9d164480", "loggedInUserPKID": 88 }'
$Result = Invoke-RestMethod -Uri $uri -Method Post -Body $body -ContentType "application/json"
# Store the token in a variable
$AccessToken = $result.token
# Set the parameters for the web API call
$params = @{
Uri = 'https://webapi.wizbangwidgets.com/ControlSetValue/UpdateControlSetValue_String'
Headers = @{Authorization = "Bearer $AccessToken"}
Method = 'POST'
Body = '{
"entityLink": <<JobNumber>>,
"entityType": "Job",
"controlSetLink": 39,
"controlGUID": "9fb6a9d5-7eae-499e-8448-46b735fba675",
"controlValue": "This is a string value has been updated via HelpMaster workflow via a Powershell script calling the web API!"
}'
ContentType = 'application/json'
}
# Call the web API
Invoke-RestMethod @params
See Also
Execute SQL as part of workflow
Control Powershell use via Application Security Roles
System Administration
Security Setting to enable/disable SQL
PowerShell Documentation
https://learn.microsoft.com/en-us/powershell/
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.