Saturday, August 12, 2023

 Azure DevOps using PowerShell REST API


Follow the steps below:
1 ) You need to record this information:
A) Organization name (https://dev.azure.com/<YOUR-ORGANIZATION-NAME-GOES-HERE>/<Project Name>
B) Project's Process Name - You need to inherit from an existing process name in order to be able to modify anything. To do that browse to: 
Locate the Process name you're using for your project you can verify that by clicking the Team projects number  - that's the <YOUR-PROCESS-NAME-GOES-HERE>
C) Find the project process ID, browse to
The result would be a in a json format
search on the page for:
"name":"{process}" there you need to look ahead till you find the first occurrence of "typeId":
its value (hash alike) is the process ID - e.g. be592as-0t41-4618-4912-055tie1096boys - that's the <YOUR-PROCESS-ID-GOES-HERE>
D) Generate a PAT (Personal Access Token) for a user with "Project collection administrator" and give it a full access rights or at least Work Items Full Access rights

Now you're good to go for the PowerShell script,
Create a file with ps1 extension and open it in your favorite IDE (e.g. Microsoft Visual Code)

Paste the code from here: (Don't forget to use the information above)

## Note:
## Locate and Replace all instances of <YOUR-...-GOES-HERE> with the values recorded above
##
function GetUrl() { param( [string]$orgUrl, [hashtable]$header, [string]$AreaId ) #Build the URL for calling the org-level Resource Acess REST API for the RM APIs $orgResourAreaUrl = [string]::Format("{0}/_apis/resourceAreas/{1}?api-version=5.0-preview.1", $orgUrl, $AreaId) # Do GET on this URL (this returens an object with a "locationUrl" field) $results = Invoke-RestMethod -Uri $orgResourAreaUrl -Headers $header # THe "locationUrl" field reflects the correct base URL for RM REST aPI calls if ("null" -eq $result) { $areaUrl = $orgUrl } else { $areaUrl = $results.locationUrl } return $areaUrl } $orgUrl = "https://dev.azure.com/<YOUR-ORGANIZATION-NAME-GOES-HERE>" $presonalToken = "<YOUR-PERSONAL-ACCESS-TOKEN-GOES-HERE>" Write-Host "Initializing authentication context" -ForegroundColor Yellow $token = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($presonalToken)")) $header = @{authorization = "Basic $token"} # Just to see all is OK - List of projects Write-Host "Checking all is OK listing your projects" # This is Microsoft core Resource Area ID - taken from https://docs.microsoft.com/en-us/azure/devops/extend/develop/work-with-urls?view=azure-devops&tabs=http $coreAreaId = "79134C72-4A58-4B42-976C-04E7115F32BF" $adoBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $coreAreaId # rest $projectsUrl = "$($adoBaseUrl)_apis/projects?api-version5.0" $projects = Invoke-RestMethod -Uri $projectsUrl -Method Get -ContentType "application/json" -Headers $header $projects.value | ForEach-Object { Write-Host $_.name } #Hide Release field from Bug template Write-Host "Hiding field Release" # This is Microsoft core Resource Area ID - taken from https://docs.microsoft.com/en-us/azure/devops/extend/develop/work-with-urls?view=azure-devops&tabs=http $coreAreaId = "79134C72-4A58-4B42-976C-04E7115F32BF" $adoBaseUrl = GetUrl -orgUrl $orgUrl -header $header -AreaId $coreAreaId $processID = "<YOUR-PROCESS-ID-GOES-HERE>" $projectsUrl="https://dev.azure.com/<YOUR-ORGANIZATION-NAME-GOES-HERE>/_apis/work/processes/" + $processID + "/workItemTypes/<YOUR-PROCESS-NAME-GOES-HERE>/layout/systemcontrols/System.Reason?api-version=6.0-preview.1" $patch_body = [pscustomobject]@{ "id:" = "System.Reason" "label" = "Reason" "controlType"= "FieldControl" "readOnly" = "false" "visible" = "false" "isCountribution" = "false" } $nessusToken = @{ "Content-Type" = "application/json" "X-SecurityCenter" = $Runjsonobj.NessusToken } $processeslist = Invoke-RestMethod -Uri $projectsUrl -Method Patch -ContentType "application/json" -Headers $header -Body ($patch_body | Convertto-Json) Write-Host $processeslist

#########
Run the script above and good luck!
Please post a comment if all wend OK or if you ran into an issue

P.S.
1) Microsoft has stated that it is mostly unlikely that they would create a WebUI option to set this configuration.



 

 Azure DevOps using PowerShell REST API Follow the steps below : 1 ) You need to record this information: A) Organization name (https://...