Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Get a report for TIcket work duration from azure devops
# Set the Selection Parameters here!!!!
# PAT Generation documented here:
# Required Permissions: Analytics (READ):; Work Items (READ)
$OrganizationName = "realcoretfs"
$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }
$uriAccount = '$filter=WorkItemType eq ''Ticket'' and year(CreatedDate) eq ' + $yearToSelect + ' &$select=WorkItemId,Title,State,ChangedDate&%orderby=CreatedDate desc'
$body = Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader
$result= New-Object -TypeName 'System.Collections.ArrayList';
$elementsToIgnore= New-Object -TypeName 'System.Collections.ArrayList';
foreach($item in $body.value)
write-host $i "von" $body.value.count
$toIgnore = $elementsToIgnore | Where-Object {$_ -eq $item.WorkItemId }
if ($toIgnore -eq $null){
# Element not exists in result list
# Get created date
$createdDate= $body.value| Where-Object {$_.WorkItemId -eq $item.WorkItemId -and $_.State -eq "New" } | select -Property ChangedDate| Select-Object -First 1
# Active date
$activeDate= $body.value| Where-Object {$_.WorkItemId -eq $item.WorkItemId -and $_.State -eq "Active" } | select -Property ChangedDate| Select-Object -First 1
# Get Closed Date
$closedDate= $body.value | Where-Object {$_.WorkItemId -eq $item.WorkItemId -and $_.State -eq "Closed" } | select -Property ChangedDate | Select-Object -First 1
# Generate object
$newObject = New-Object -TypeName PSObject -Property @{
ID = $item.WorkItemId
Title = $item.Title
CreationDate= $createdDate.ChangedDate
ActiveDate= $activeDate.ChangedDate
ClosedDate= $closedDate.ChangedDate
DurationFromNewtoClose = New-TimeSpan -Start $createdDate.ChangedDate -End $closedDate.ChangedDate
# add to result
$x= $result.Add($newObject);
Write-host "Element Proceeded"
$result | Export-Csv "Ticket.csv"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment