How to connect to Autotask WebAPI using powershell

Autotask is our MSP tool of choice. It has all the functions we need and then some. One of its more powerful features is a Web Services API. We use it to automatically download and import invoice information into our ERP system and perform some batch updates that would be very bothersome to do manually. I made our invoice import tool in .NET, but batch updates are much easier to do in PowerGUI with Powershell.

To get started you need to know your web services URL. You’ll find it in the API documentation, but let us make it our first task to use powershell to get it.

First of all we need to create a WebServiceProxy object with your Autotask credentials. As always, you can either use Get-Credential (this is definitely the more secure option) or you may use cleartext in your code. I have created a special user on Autotask just for Web Services use, but any user with sufficient permissions will do.

Since we do not yet know which web services URL to use, we start with the first one;</a>

# Username and password for Autotask 

# The username must begin with a backslash, otherwise Windows will add a domain
# element that Autotask do not understand.
$username = '[email protected]'
$password = ConvertTo-SecureString 'your_autotask_password' -AsPlainText -Force
$credentials = New-Object System.Management.Automation.PSCredential($username,$password) 

# Web services URL for Autotask definert direkte i opprettelsen av SOAP objektet
$atws = New-WebServiceProxy -URI -Credential $credentials

# Now, lets make our first query
$zoneInfo = $atws.getZoneInfo($username)

# This is the URL you should use in line 10 for the future
If ($zoneInfo.ErrorCode -eq 0)
    Write-Host $zoneInfo.URL
    Write-Host 'Something went wrong!'

To use this info automatically you may expand line 10 into this:

$atws = New-WebServiceProxy -URI -Credential $credentials
$zoneInfo = $atws.getZoneInfo($username)
$atws = New-WebServiceProxy -URI $zoneInfo.URL -Credential $credentials

Now you have a powershell WebServicesProxy object that you can use query and update your Autotask data from powershell.