【问题标题】:Download audit logs in csv from azure DevOps UI using powershell使用 powershell 从 azure DevOps UI 下载 csv 中的审计日志
【发布时间】:2023-03-26 17:15:01
【问题描述】:

您好,我正在寻找一个脚本,它可以在给定的时间范围内使用 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

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

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

我找不到更多关于此的数据

【问题讨论】:

  • 回答:可能是的。请向我们展示您已经尝试过的代码。添加有关未按预期工作的信息、您可能收到的可能错误消息等信息。
  • @Theo 我只用为此找到的脚本更新了代码,但我不确定我需要在脚本中输入的值。我也尝试使用 rest api 获取审计日志,但它不能证明这里的所有数据都是问题发布 -stackoverflow.com/questions/64392632/…
  • 嗨@megha,我已经更新了 API 并添加了时间范围,现在您可以使用 powershell 在给定时间范围内从 azure DevOps 下载 csv 格式的导出日志。您可以尝试并在此处分享结果。谢谢。
  • 嗨@megha,刚刚签到看看这个问题现在是否仍然阻碍你?这个问题有什么更新吗?

标签: powershell automation azure-devops azure-devops-analytics


【解决方案1】:

您分享的示例是从 Azure DevOps Server 下载审核日志,网址为 https://{your_server}/tfs/_api/_licenses/Export,用户名、密码是您登录 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

结果:

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-02-07
  • 1970-01-01
  • 1970-01-01
  • 2021-01-31
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多