PowerShell

PowerShell: Autotask – Get Picklist Values

Originally published on TechColumnist.

When using Autotask’s API it’s required to lookup a various amount of picklist values that are used in updating your web request. This is a PowerShell way to pull those picklist values. The first part of the script validates your AT URI, the second part gets the entity data, in this case I was looking for “ticket” related fields.

Edit: Updated to give a more friendly output

Requirements

  • Windows PowerShell 2.0 or later. New-WebServiceProxy is not available in PowerShell 6 and later.
  • An Autotask user with API access (username and password).
  • HTTPS access to the Autotask web services (webservices1.autotask.net and the zone URL that getZoneInfo returns).

Parameters

The script takes no parameters. Edit these values before running it.

NameTypeRequiredDescription
$ATurlStringYesStarting WSDL used to look up your zone. It is replaced with the zone URL that getZoneInfo returns.
$ATusernameStringYesAutotask API username. Replace <autotask-username>.
$ATpasswordStringYesPassword for that user. Replace <autotask-password>.
"Ticket"StringNoEntity passed to getFieldInfo. Change it to list the picklists of another entity.

Usage

Fill in the username and password, then run the script.

powershell
.\Get-AutotaskPicklistValues.ps1

For each field in the entity it prints the name, label and description, followed by the picklist values (Label, Value, IsActive). It ends with your API threshold and usage message.

To look at another entity, change the entity name in the getFieldInfo call.

powershell
$entity = $atws.getFieldInfo("Account")

Script

powershell
<#
.SYNOPSIS
    Lists the picklist values for an Autotask entity (Ticket by default) through the Autotask SOAP API.
.DESCRIPTION
    Connects to the Autotask web service with the given credentials, looks up the zone for the user
    and reconnects to the zone WSDL. It then calls getFieldInfo for the Ticket entity and prints each
    field with its picklist values, and finishes by printing the API threshold and usage message.
.EXAMPLE
    .\Get-AutotaskPicklistValues.ps1
.NOTES
    Author  : Thomas Lasswell (https://www.techcolumnist.com)
    Version : 1.0 (2015-02-06)
    Requires: Windows PowerShell 2.0+ (New-WebServiceProxy), an Autotask API user
#>
# Username and password for Autotask.
$ATurl = "https://webservices1.autotask.net/atservices/1.5/atws.wsdl"
$ATusername = "<autotask-username>"
$ATpassword = ConvertTo-SecureString "<autotask-password>" -AsPlainText -Force
$ATcredentials = New-Object System.Management.Automation.PSCredential($ATusername, $ATpassword)

# Look up the zone for this user and connect to it.
$atws = New-WebServiceProxy -Uri $ATurl -Credential $ATcredentials
$zoneInfo = $atws.getZoneInfo($ATusername)
$ATurl = $zoneInfo.URL.Replace(".asmx", ".wsdl")
$atws = New-WebServiceProxy -Uri $ATurl -Credential $ATcredentials

# Get the field information for the entity.
$entity = $atws.getFieldInfo("Ticket")

foreach ($picklist in $entity) {
    $picklist | Select-Object Name, Label, Description | Format-Table
    foreach ($values in $picklist.PicklistValues) {
        $values | Select-Object Label, Value, IsActive
    }
}

# Show the API threshold and usage information.
$output = $atws.getThresholdAndUsageInfo()
$output.EntityReturnInfoResults.message