Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Azure Devops使用powershell审核rest api延续令牌_Powershell_Azure Devops_Azure Devops Rest Api - Fatal编程技术网

Azure Devops使用powershell审核rest api延续令牌

Azure Devops使用powershell审核rest api延续令牌,powershell,azure-devops,azure-devops-rest-api,Powershell,Azure Devops,Azure Devops Rest Api,我正在编写脚本,该脚本应将选定字段的审核日志报告输出到csv文件中。由于RESTAPI结果的限制,我不能一次获取所有数据。 若我手动传递延续令牌,我可以获得下一组数据,但我希望脚本生成给定时间范围内的所有日志 我尝试了这个脚本,它不会返回所有数据- $personalAccessToken = "" $auth = [Convert]::ToBase64String([Text.Encoding]:: ASCII.GetBytes(&quo

我正在编写脚本,该脚本应将选定字段的审核日志报告输出到csv文件中。由于RESTAPI结果的限制,我不能一次获取所有数据。 若我手动传递延续令牌,我可以获得下一组数据,但我希望脚本生成给定时间范围内的所有日志

我尝试了这个脚本,它不会返回所有数据-

$personalAccessToken = ""
$auth = [Convert]::ToBase64String([Text.Encoding]::                  
ASCII.GetBytes(":$($personalAccessToken)"))

$headers = @{}
$headers.Add("Authorization", "Basic $auth")


do
{
$uri = "https://auditservice.dev.azure.com/{org}/_apis/audit/auditlog?      
startTime=2020-07-01T00.00.00&endTime=2020-10-   
15T16.00.00&continuationToken=$continuationToken&api-version=6.0-
preview.1"

$TestRuns = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get    
| Select-Object -ExpandProperty decoratedAuditLogEntries | 
Where-Object { $_.actionId -eq 'Git.RepositoryCreated' } |
Select-Object actorDisplayName, ProjectName, actionId, details, 
timestamp  
$continuationToken = $TestRuns.Headers.'x-ms-continuationtoken'

$TestRuns
}
while ($continuationToken -ne $null)
我还尝试了Invoke webrequest,它也不提供所有数据。我有一大堆圆木


如何获取所有数据?

以下是对我有效的解决方案-

$personalAccessToken = ""
$auth =  
[Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes
(":$($personalAccessToken)"))

$headers = @{}
$headers.Add("Authorization", "Basic $auth")

do
{
$uri =     
"https://auditservice.dev.azure.com/{organization}/_apis/audit/auditlog?  
startTime=2020-09-20T20:42:20:3094806Z&endTime=2020-10-
15T20:42:20:3094806Z&continuationToken=$continuationToken&api-version=6.0-
preview.1"

$TestRuns = Invoke-RestMethod -Uri $uri -Headers $headers -Method Get 

$result = @( $TestRuns | Select-Object -ExpandProperty     
decoratedAuditLogEntries | 
Where-Object { $_.actionId -eq 'Git.RepositoryCreated' } |
Select-Object actorDisplayName, ProjectName, actionId, details, 
timestamp )

$continuationToken = $TestRuns.continuationToken 

$result | Export-Csv "/data.csv" -Append
}

while ($null -ne $continuationToken)

您是否从管道中运行此脚本?然后你可以考虑一个被管理的身份,以避免替换授权令牌。不,我在本地PCC上运行这个脚本。这回答了你的问题吗?@马特我已经更新了上面的答案,这也不是给我所有的数据后,某些输入它停止创造!谢谢你在这里分享你的解决方案,你可以接受它作为答案,这样它可以帮助其他社区成员谁得到同样的问题,我们可以存档这个线程,谢谢。