Created
June 14, 2021 14:07
-
-
Save vinijmoura/0de7d133c295b61769b5bccbd076328b to your computer and use it in GitHub Desktop.
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
| Param | |
| ( | |
| [string]$PAT, | |
| [string]$Organization, | |
| [string]$Connstr | |
| ) | |
| $SQLQuery = "TRUNCATE TABLE TaskGroups" | |
| Invoke-Sqlcmd -query $SQLQuery -ConnectionString $Connstr | |
| $AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($PAT)")) } | |
| $UriOrganization = "https://dev.azure.com/$($Organization)/" | |
| $uriProject = $UriOrganization + "_apis/projects?`$top=500" | |
| $ProjectsResult = Invoke-RestMethod -Uri $uriProject -Method get -Headers $AzureDevOpsAuthenicationHeader | |
| Foreach ($project in $ProjectsResult.value) | |
| { | |
| $uriTaskGroups = $UriOrganization + "$($project.id)/_apis/distributedtask/taskgroups?api-version=6.1-preview.1" | |
| $TaskGroupsResult = Invoke-RestMethod -Uri $uriTaskGroups -Method get -Headers $AzureDevOpsAuthenicationHeader | |
| Foreach ($taskgroup in $TaskGroupsResult.value) | |
| { | |
| Foreach ($tgt in $taskgroup.tasks) | |
| { | |
| $SQLQuery = "INSERT INTO TaskGroups ( | |
| TeamProjectName, | |
| TaskGroupId, | |
| TaskGroupName, | |
| TaskGroupIconURL, | |
| TaskGroupVersion, | |
| TaskGroupCategory, | |
| TaskGroupTaskDisplayName, | |
| TaskGroupTaskReferenceId, | |
| TaskGroupTaskVersionSpec, | |
| TaskGroupTaskEnabled | |
| ) | |
| VALUES( | |
| '$($project.name)', | |
| '$($taskgroup.id)', | |
| '$($taskgroup.name)', | |
| '$($taskgroup.iconUrl)', | |
| '$($taskgroup.version.major.ToString() + '.' + $taskgroup.version.minor.ToString() + '.' + $taskgroup.version.patch.ToString())', | |
| '$($taskgroup.category)', | |
| '$($tgt.displayName.Replace('$',''))', | |
| '$($tgt.task.id)', | |
| '$($tgt.task.versionSpec)', | |
| '$($tgt.enabled)' | |
| )" | |
| $SQLQuery | |
| Invoke-Sqlcmd -query $SQLQuery -ConnectionString $Connstr | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment