**** This entire article now available as a white paper for download here >>  ****

There are currently two main options used to run PowerShell scripts from ServiceDesk Plus, the ‘Request Custom Menu’ or ‘Custom Trigger’ options, available from ‘Admin > HelpDesk Customiser’. Both of these configurations will have an option to execute a script and, in order to run a PowerShell script, you will need to use the following command as an ‘Execute Script’ action:

cmd /c powershell.exe -WindowStyle Hidden -file c:ManageEngineServiceDeskintegrationcustom_scriptstestscript.ps1 $COMPLETE_JSON_FILE

The use of the tag $COMPLETE_JSON_FILE is only needed when you want to send your PowerShell script the output data of the request from where the script is being actioned or triggered. This is useful for getting information such as the Request ID if you’re looking to interact with the request from which the PowerShell script was actioned. You can pass individual request data values, e.g. $ASSET, but you might as well send details of the whole request and split out the required values as needed in the PowerShell script.

So for a real scenario … one client we were working with had a new starter process that required an email to be delivered to a specific team that were not part of the ServiceDesk installation with details of the ticket if a particular level of access was requested. 

In order to achieve this we designed a Service Request template with all the necessary data fields and resource elements to collect the required data for the new starter process. On this template was a specific custom field that we used to specify the particular access level and this was used as a trigger condition for a ‘Custom Trigger’ with the full request data being passed to the script as $COMPLETE_JSON_FILE. 

An example is shown below:


Here is the PowerShell script we created to send the email with the required contents of the request; the actual script also included a large number of custom fields but I’ve only included the standard SDP request fields in this example. I’ve also kept the data in the JSON format as this easier to relate to and test when using the API Documentation feature in the ServiceDesk Plus Admin tab. Remember to save your script file to the ‘integrationcustom_scripts’ folder if you’re going to test a copy:

——– Start of script ——-
# V1.0 Initial release
# V1.1 Updated to use API to send Email as Reply to Request rather than PowerShell 
# MailMessage Cmdlet

# Store request data passed to script – this must be first element in script 
param (
$json = “none”

$jsondata = Get-Content $json -Encoding UTF8   #Encode if necessary
$obj = ConvertFrom-Json $jsondata

# Add Request fields values as needed – custom fields are referenced by their alias name
$workorderid = $obj.request.WORKORDERID
$requester = $obj.request.REQUESTER
$createdtime = $obj.request.createdtime
$subject = $obj.request.SUBJECT
$category = $obj.request.category
$technician = $obj.request.technician
$status = $obj.request.status
$priority = $obj.request.priority
$requesttype = $obj.request.requesttype
$group = $obj.request.group
$description = $obj.request.description

# Set system parameters – change these details to suit your system environment
$sdphost = “http://[hostname or IP address]:[port]/”
$techkey = “[your technician API key]

# Set API module URL and operation – this is the URL for calling the request API
# It uses the request parameter passed to the script $workorderid
$url = $sdphost + “sdpapi/request/” + $workorderid
$method = “POST”
$operation = “REPLY_REQUEST”

# Define Email Content
$to = ” [insert to email address here] ”
$cc = ” [insert cc email address here] 
$subject = “New Starter Alert”

# email description text 
$body = “Request Number : $workorderid, Requester : $requester, Subject : $subject, Category : $category, Technician: $technician, Status : $status, Priority : $priority, Request Type: $requesttype, Group : $group”

# Configure input data for email Reply operation in JSON format
$inputdata = @”
“operation”: {
“details”: {
“to”: “$to”,
“cc”: “$cc”,
“subject”: “$subject”,
“description”: “$body”

# Configure paramaters for web API call as an array of object and format as JSON data – this is a more elegant method than creating a text string to build the URL

$params = @{INPUT_DATA=$inputdata;OPERATION_NAME=$operation;TECHNICIAN_KEY=$techkey;format=’json’}

# Make a web API call and record result
$response = Invoke-WebRequest -Uri $url -Method POST -Body $params

——– End of script ——-

I hope this series of blog articles has been useful. I’m finding that there are ever more customer requirements for using scripts and the API in general. I will be including more examples in future posts and also uploading them to the Forum Resources but that’s all on the ServiceDesk Plus API for now.


This article is relevant to:
Service Desk

You may be interested in these other recent articles

Get to building your business apps with the new AppCreator

9 June 2022

ManageEngine’s new low-code application development tool Creating an application, building one and deploying it can be expensive and time consuming as you have to make…

Read more

Endpoint Central’s Endpoint Security

31 May 2022

Endpoint Central (formerly Desktop Central) not only got a name change but has also introduced Endpoint Security to help organisations keep their endpoints secured. According…

Read more

Automation in ManageEngine ServiceDesk Plus

20 December 2021

Increasingly customers are looking to automate repetitive and mundane tasks in ServiceDesk Plus. Since the introduction of Deluge, Zoho’s online scripting language, as part of…

Read more

Update on the recent Apache Log4j2 vulnerability – Impact on ManageEngine on-premise and Zoho cloud products

14 December 2021

A high severity vulnerability (CVE-2021-44228) impacting multiple versions of the Apache Log4j2 utility was disclosed publicly on December 9, 2021. The vulnerability impacts Apache Log4j2…

Read more

Who do I contact for technical support for my ManageEngine product?

10 September 2021

When purchasing a ManageEngine product it will either have been supplied on a subscription basis or it would have included an initial Annual Maintenance and…

Read more