我正在尝试使用PowerShell中的REST API使用下面的代码在TFS中创建一个错误,但是我无法弄清楚如何使用这些参数和数据的名称填充$Bug
变量。
Param(
[string]$vstsAccount = "MyAccountName",
[string]$projectName = "ProjectName",
[string]$keepForever = "true",
[string]$user = "",
[string]$token = "Mytoken"
)
# Base64-encodes the Personal Access Token (PAT) appropriately
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
#$uri = "https://$($vstsAccount).visualstudio.com/$($projectName)/_apis/wit/workitems/$Bug?api-version=2.2"
$result = Invoke-RestMethod -Uri $uri -Method Get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)}
我可以找到C#here的示例,但不能找到PowerShell的示例。任何帮助将不胜感激。
干杯
答案 0 :(得分:3)
您需要创建 JSON正文以使用REST API在PowserShell中创建工作项,Content-Type
应为application/json-patch+json
,同时使用{{1 }} 方法。有关详细信息,请参阅Create a work item。
您可以参考下面的示例PowerShell脚本来创建错误:
PATCH