0

Am working on PowerShell script where I am trying to get project id of an existing one in Azure DevOps account. For that, am used following script:

$AzureDevOpsPAT = "l7zybu-XXX-XXXX-XXXXX"
$OrganizationName = "OrgName"
$projectName = "XXXXXX"

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$UriOrga = "https://$($OrganizationName).visualstudio.com/" 
$UriOrga
$uriAccount = $UriOrga + "_apis/projects?api-version=6.0"
Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader | where({ $_.name -eq $projectName })

After running this script am not getting any type of Output in logs, it's just executing? Could you please help me to find solution for this.

1
  • 1
    That's because you're filtering the results.with | where({ $_.name -eq $projectName }) and there isn't a match. Remove that and see what it returns. Commented Feb 18, 2021 at 18:29

1 Answer 1

1

How to get project id for an existing Azure DevOps project using PowerShell?

You could try the following PowerShell Sample:

$AzureDevOpsPAT = "PAT"

$OrganizationName = "organizaitonName"
$projectName = "Projectname"

$AzureDevOpsAuthenicationHeader = @{Authorization = 'Basic ' + [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(":$($AzureDevOpsPAT)")) }

$UriOrga = "https://$($OrganizationName).visualstudio.com/" 
$UriOrga
$uriAccount = $UriOrga + "_apis/projects?api-version=6.0"
$response = Invoke-RestMethod -Uri $uriAccount -Method get -Headers $AzureDevOpsAuthenicationHeader 


$Project = $response.value | where { $_.Name -eq $projectName }

$id = $Project.id

echo $id

The response returned by Rest API is in Json format, so you can get the json response first, and then directly obtain the corresponding project id through comparison

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.