首页 > 解决方案 > 使用 powershell 从 azure DevOps UI 下载 csv 中的审计日志

问题描述

嗨,我正在寻找一个脚本,它可以在给定的时间范围内使用 powershell 从 azure DevOps 下载 csv 中的导出日志。就像我可以输入时间范围,然后脚本将从 azure DevOps ui 下载并返回 csv 文件 -

在此处输入图像描述

我在这里找到了这个脚本https://developercommunity.visualstudio.com/content/problem/615053/question-we-want-to-get-the-export-audit-log-using.html

我不确定在这里使用什么用户名、密码和 url

$Username = 'domain\user'
$Password = 'password'
$Url = "https://server:8080/tfs/_api/_licenses/Export"
$Path = "D:\temp\data.csv"
$WebClient = New-Object System.Net.WebClient
$WebClient.Credentials = New-Object    
System.Net.Networkcredential($Username, $Password)
$WebClient.DownloadFile( $url, $path )

我无法找到更多关于此的数据

标签: powershellautomationazure-devopsazure-devops-analytics

解决方案


您分享的示例是从 Azure DevOps Server 下载审核日志,url 是https://{your_server}/tfs/_api/_licenses/Export, username , password 是您登录 TFS 的用户名和密码。注意:不要忘记在用户名前添加域名。

如果您使用的是 Azure DevOps 服务,则可以尝试使用此REST API和 power shell 脚本来保存审核日志。

$outfile = "{Local path}"
$connectionToken="{PAT}"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($connectionToken)"))
$AuditLogURL = "https://auditservice.dev.azure.com/{organization}/_apis/audit/downloadlog?format=csv&startTime={startTime}&endTime={endTime}&api-version=6.1-preview.1" 
$AuditInfo = Invoke-RestMethod -Uri $AuditLogURL -Headers @{authorization = "Basic $base64AuthInfo"} -Method Get –OutFile $outfile

结果:

在此处输入图像描述


推荐阅读