Last active
December 11, 2018 12:15
-
-
Save WimObiwan/a1d21ea6688b43645f32fa8e39eef1c2 to your computer and use it in GitHub Desktop.
AutoTask
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# one-time installation | |
Install-Module -Name Autotask | |
# initialize | |
Import-Module Autotask | |
$Credential = Get-Credential | |
Connect-AutotaskWebAPI -Credential $Credential | |
function ArrayToHash($a) | |
{ | |
$hash = @{} | |
$a | %{ $hash[$_.Value] = $_.Label } | |
return $hash | |
} | |
# get status & queue mappings | |
$fieldinfo = Get-AtwsFieldInfo "Ticket" | |
$statuslist = ArrayToHash(($fieldinfo | ?{ $_.Name -eq 'status'})[0].PickListValues) | |
$queuelist = ArrayToHash(($fieldinfo | ?{ $_.Name -eq 'queueid'})[0].PickListValues) | |
# load non-complete tickets | |
$tickets = Get-AtwsTicket -Status 'Complete' -NotEquals 'Status' | |
# resolve queue and status | |
$tickets2 = ` | |
$tickets ` | |
| select ` | |
TicketNumber, ` | |
CreateDate, ` | |
@{Name='Queue'; Expr={$queuelist[[string]$_.QueueId]}}, ` | |
@{Name='Status'; Expr={$statuslist[[string]$_.Status]}} | |
# tickets per Queue/Status | |
$tickets2 ` | |
| Group-Object Queue, Status ` | |
| select Name, Count ` | |
| sort Name | |
# tickets per Queue/Status, with first/last ticket | |
$tickets2 ` | |
| group Queue, Status ` | |
| sort Name ` | |
| select ` | |
Name, ` | |
Count, ` | |
@{Name='First'; Expr={ ($_.Group.CreateDate | measure -Min).Minimum } }, ` | |
@{Name='Last'; Expr={ ($_.Group.CreateDate | measure -Max).Maximum } } | |
# tickets per Queue/Status | |
$tickets2 ` | |
| group Queue, Status ` | |
| select @{Name="Queue";Expr={$_.Group[0].Queue}}, @{Name="Status";Expr={$_.Group[0].Status}}, Count ` | |
| sort Queue, Status ` | |
| ConvertTo-Csv ` | |
#> .\tickets.csv | |
# tickets per Queue/Status (split queue/status, correct headings, tab-delimiter) | |
$tickets2 ` | |
| group Queue, Status ` | |
| select @{Name="Queue";Expr={$_.Group[0].Queue}}, @{Name="Status";Expr={$_.Group[0].Status}}, Count ` | |
| sort Queue, Status ` | |
| ConvertTo-Csv -Delimiter "`t" -NoTypeInformation ` | |
#> .\tickets-v2.csv |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment