当我输入命令来检索特定项目中的所有查询时,即: https://dev.azure.com/{organization}/{project}/_apis/wit/queries?$深度=4&api-version=7.1-preview.2 我得到的结果显示 Json 格式的顶层文件夹“我的查询”和“共享查询”以及驻留在这些文件夹中的所有查询。 但是,当将相同的 uri 粘贴到 powershell 脚本中时,它只会给我两个顶层文件夹;因此我无法搜索“叶子”。
Powershell:
$user = "my patcode"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$posturl= "https://dev.azure.com/{organization}/{project}/_apis/wit/queries?$depth=2&api-version=7.1-preview.2"
Invoke-RestMethod -Uri $PostUrl -Method get -ContentType "application/json" -Headers @{Authorization= ("Basic {0}" -f $base64AuthInfo)}|convertto-json
这里有两点:
在 URL 中使用“/queries?`$深度”,因为 poweshell 尝试使用 $深度变量。
使用 convetto-json 中的深度参数
$posturl= "https://dev.azure.com/{org}/{project}/_apis/wit/queries?`$depth=2&api-version=7.1-preview.2"
Invoke-RestMethod -Uri $PostUrl -Method get -ContentType "application/json" -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} | ConvertTo-Json -Depth 100
我可以与您重现相同的问题,请按照以下步骤修复:
Invoke-WebRequest
cmdlet 而不是 Invoke-RestMethod
。由于 PowerShell 中的 Invoke-RestMethod cmdlet 会自动将 JSON 内容转换为 PowerShell 对象,这可能会从输出中排除 children
(查询详细信息)。脚本如下:
$token = "PAT"
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f $user,$token)))
$headers = @{
Authorization = ("Basic {0}" -f $base64AuthInfo)
}
$response = Invoke-WebRequest -Uri "https://dev.azure.com/{org}/{project}/_apis/wit/queries?`$depth=2&api-version=7.1-preview.2" -Headers $headers
$response.Content
查询详情回复: