通过REST API Powershell脚本检查“允许所有管道”

时间:2020-06-07 16:59:15

标签: azure powershell azure-devops azure-devops-rest-api

我正在尝试通过Azure DevOps Rest API启用“允许所有管道”:

Private Sub Userform.Initialize()
    If Worksheets("Sheet1").Range("P1").Value = "Y" _
        Then
        CheckBox1.Value = True
        Else
        CheckBox1.Value = False
    End If
End Sub

只有powershell给我以下错误:

$uri = "https://dev.azure.com/**/**/_apis/pipelines/pipelinePermissions/endpoint/" + $ID + "?api-version=5.1-preview.1"


$Allowpipelines =   "[{ 

    ""allPipelines"": {
    ""authorizedBy"": null,
    ""authorizedOn"": null,
    ""authorized"": true,
    ""id"": ""$ID"",
    ""name"": ""Kubernetes"",
    ""type"": ""endpoint""
  }
}]" 

$output = Invoke-RestMethod -Uri $uri -Method Patch -Headers $AzureDevOpsAuthenicationHeader -ContentType "application/json"

echo $output

身体通过邮递员工作,但是对于天蓝色的虔诚者,我想通过Powershell使其工作

1 个答案:

答案 0 :(得分:0)

经过一些故障排除后,我发现我在json正文之后放了一个问题

感谢您的时间和精力!

最终代号:

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

$baseUri = "https://dev.azure.com/$($OrganizationName)/$($ProjectName)/";
$uri = $baseUri + "/_apis/pipelines/pipelinePermissions/endpoint/"+ $ID + "?api-version=5.1-preview.1"


$Allowpipelines = @{
    "allPipelines"= @{
        "authorized"= "true"
        "authorizedBy"= "null"
        "authorizedOn"= "null"
    }
    "pipelines"= "null"
    "resource"= @{
        "id"= "${ID}"
        "type"= "endpoint"
    }
} | ConvertTo-Json -Depth 5



$output = Invoke-RestMethod -Uri $uri -Method Patch -Headers $AzureDevOpsAuthenicationHeader -Body $Allowpipelines -ContentType "application/json"