[英]How to get project id for an existing Azure DevOps project using PowerShell?
Am working on PowerShell script where I am trying to get project id of an existing one in Azure DevOps account.我正在处理PowerShell脚本,我试图在Azure DevOps帐户中获取现有项目的项目 ID。 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?运行此脚本后,在日志中没有得到任何类型的 Output,它只是在执行? Could you please help me to find solution for this.
你能帮我找到解决方案吗?
How to get project id for an existing Azure DevOps project using PowerShell?
如何使用 PowerShell 获取现有 Azure DevOps 项目的项目 ID?
You could try the following PowerShell Sample:您可以尝试以下 PowerShell 示例:
$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 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.