简体   繁体   English

如何使用 PowerShell 获取现有 Azure DevOps 项目的项目 ID?

[英]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.

相关问题 如何使用 powershell/Azure CLI 列出对 Azure DevOps 项目 repo 具有权限的用户? - How to list the user who has permissions to the Azure DevOps project repo with powershell/ Azure CLI? 在本地使用 PowerShell 在分支上获取 Azure DevOps last build id - Use PowerShell locally to get Azure DevOps last build id on branch 获取 Azure DevOps 服务连接服务主体 id 与 powershell - Get Azure DevOps service connection service principal id with powershell Azure CLI DevOps 使用 PowerShell 获取已创建项目的 ID - Azure CLI DevOps get ID of created item with PowerShell 使用PowerShell将现有项目添加到解决方案文件夹 - Add an existing project to solution folder using PowerShell 如何使用 powershell(Azure devops REST API)获取用户提交更改的 Azure devops git repo 文件夹名称 - How to get Azure devops git repo folder name where user committed changes using powershell (Azure devops REST API) 使用Powershell 2部署Azure项目的问题 - Issue with deploying Azure project using Powershell 2 如何使用 Z2F2D399F0EA88447359FE5514B0Z 应用程序在 azure web 应用程序中获取 object id - how to get the object id in azure web app using powershell command 如何使用 PowerShell 获取 Azure 资源的对象 ID - How to get Object Id of Azure Resource using PowerShell 使用 Powershell 以纯文本形式获取 Azure Devops Secret Variable - Get Azure Devops Secret Variable as Plain Text using Powershell
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM