Go to Automation > PowerShell Scripts to get started.
Create a PowerShell script
In this example, we'll create a script that retrieves the current weather conditions for a given city from the MetaWeather API.
- Select the New PowerShell Script button.
- The General tab contains four fields:
The script's name. For this example, we'll use
Local Weather Report.
The script's description (optional).
Disabled scripts are not available to be assigned to tasks.
Your PowerShell code. For this example, we'll paste the following script. It contains custom HelloID cmdlets.
$locationEndpoint = "https://www.metaweather.com/api/location/search/?query=$city" Hid-Write-Status -Message "Looking up location of $city" -Event Information $locationResponse = Invoke-RestMethod -uri $locationEndpoint $location = $locationResponse.woeid $forecastEndpoint = "https://www.metaweather.com/api/location/$location" Hid-Write-Status -Message "Getting weather information for $city" -Event Information $forecastResponse = Invoke-RestMethod -uri $forecastEndpoint $temp = $forecastResponse.consolidated_weather.the_temp $weather = $forecastResponse.consolidated_weather.weather_state_name Hid-Write-Summary -Message "Current $city Temperature: $temp" -Event Information -Icon fa-cloud Hid-Write-Summary -Message "Current $city Condition: $weather" -Event Information -Icon fa-cloud
- On the Variables tab, you can define local variables to reference in your script using
$variableNamesyntax. For this example, add a single variable with Type
city, and Value
- Select the Save button.
- The newly-created standalone PowerShell script is now available on the PowerShell Scripts Overview screen.
Add a standalone PowerShell script to a task
For the above example, name the task
Local Weather Report. Turn on the Use Template toggle and select the
Local Weather Report PowerShell script as the Template.
Use a PowerShell script inside a task
Now that you've created a task which runs your standalone PowerShell script, you can use the task wherever tasks are supported.
To test the task, run it manually. For this example, the
Local Weather Report task will fetch and report London's weather via the MetaWeather API:
This example merely reports the current weather in the task summary. However, it shows the potential of custom PowerShell in your HelloID environment. You can write scripts that work with your organization's internal infrastructure, query external APIs, or anything else you need.
For some examples of PowerShell-based tasks designed for use with Active Directory, see the Active Directory Task docs section.