如何通过 PowerShell 创建 Azure DevOps 服务连接端点

How to create Azure DevOps Service connection endpoints through PowerShell

我想知道是否可以编写 PowerShell 来创建 Azure DevOps 服务连接端点。

我想限制每个人访问 Azure DevOps 以创建服务连接端点,我们需要创建多个服务连接端点,包括单元测试工具、构建工具、自动化测试工具的连接端点,然后 docker 事物。

我可以使用 PowerShell (Invoke-RestMethod <uri> -Method get -Header <myheader>) 通过 Azure DevOps Rest API 读取已经创建的 Azure DevOps 服务连接端点,但是我想知道是否可以使用相同的 Rest API 通过将服务端点信息作为 Body 传递给 Rest API (Invoke-RestMethod)。

这是我获取现有服务连接端点的方法:

##Invoke-RestMethod $url -Method GET -Headers $headers -ContentType 
'application/json' -Verbose

##I refer below code as Example to code to update existing work item, 
this is working but for service connection endpoint, I'm having no clue:
$workitem = Invoke-RestMethod -Uri $wisUrl -Method Get -ContentType 
"application/json" -Headers $header
Write-Host "Before: $($workitem.fields.'System.Title')"

$body = @" 
[
  {
    "op": "add",
    "path": "/fields/System.Title",
    "value": "$($workitem.fields.'System.Title')+DEMO"
  },
  {
    "op": "add",
    "path": "/fields/System.History",
    "value": "Changing Title"
  }
] 
"@

$workitem = Invoke-RestMethod -Uri $wisUrl -Method Patch -ContentType 
"application/json-patch+json" -Headers $header -Body $body
Write-Host "After: $($workitem.fields.'System.Title')"

有可能 Endpoints - Create Rest API:

POST https://dev.azure.com/{organization}/{project}/_apis/serviceendpoint/endpoints?api-version=5.1-preview.2

请求正文,例如(对于 Azure 端点):

{
  "data": {
     "SubscriptionId": "21312421-4123-1323-3123-12534543",
     "SubscriptionName: "TestSub"
  },
  "id": "2e344hjds-23ds-242fs-42ds-dsfsdaf34s",
  "name": "TestEndpoint",
  "type": "Azure",
  "authorization": {
    "parameters": {
       "Certificate": "dummyCertificate"
     },
     "scheme": "Certificate"
  },
  "isReady": false
}