Azure Devops audit rest api continuation token using powershell

后端 未结 1 992
遥遥无期
遥遥无期 2021-01-28 10:51

I am working on script which should output audit logs report in csv file for selected fields. Due to rest api result limitation I can not get all data at once. If I pass continu

相关标签:
1条回答
  • 2021-01-28 11:23

    Here is the solution which worked for me -

    $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)
    
    0 讨论(0)
提交回复
热议问题