通过 REST API Powershell 脚本检查 "Allow all pipelines"

check "Allow all pipelines" through REST API Powershell script

我正在尝试通过 Azure DevOps Rest API:

启用 "Allow all pipelines"
$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 会出现以下错误:

    Invoke-RestMethod : {"$id":"1","innerException":null,"message":"TF400898: An Internal Error Occurred.
 Activity Id: 83a861fb-92ad-4f42-9007-452ca806f524.","typeName":"System.NullReferenceException, mscor
lib","typeKey":"NullReferenceException","errorCode":0,"eventId":0}
At line:2 char:14
+ ... Output= Invoke-RestMethod -Uri $uri -Method Patch -Header ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-R 
   estMethod], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRest 
   MethodCommand

主体通过 postman 工作,但对于 azure devops,我希望通过 Powershell 使其工作

经过一些故障排除后,我发现了问题,我在 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"