Azure Devops audit rest api continuation token using powershell

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 continuation token manually I can get next set of data but I want script to generate all logs for given time frame

I tried this script which does not return all data -

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

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

$uri = "{org}/_apis/audit/auditlog?      

$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, 
$continuationToken = $TestRuns.Headers.'x-ms-continuationtoken'

while ($continuationToken -ne $null)

I also tried with Invoke-webrequest it also does not provide all data. I have large chuck of logs.

How can I get all the data ?

Read more here:

Content Attribution

This content was originally published by Megha at Recent Questions - Stack Overflow, and is syndicated here via their RSS feed. You can read the original post over there.

%d bloggers like this: