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
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)