首页 > 解决方案 > Azure Powershell cmd-let - Get-AzureRmLog 不显示“Microsoft.Authorization/”日志

问题描述

我准备了 Azure PowerShell 脚本,用于从 Azure 活动日志中捕获 RBAC 更改信息。当我在我的测试订阅上测试这个脚本时,脚本工作正常。问题是当我使用connect-azurermaccount -subscription命令并切换到产品订阅时。在 Azure 活动日志刀片中,我看到有一些与 RBAC 更改相关的日志,例如“创建角色分配”之类的日志名称。我正在使用如下命令进行测试:

Get-AzureRmLog -StartTime (Get-Date).AddDays(-10) | 
Where-Object {$_.Authorization.Action -like 
"Microsoft.Authorization/roleAssignments/*"}

Get-AzureRmLog -StartTime 2019-09-01T10:30 | Where-Object {$_.Authorization.Action -like "*Microsoft.Authorization/*"}

我没有在控制台中看到任何输出。当我登录到 Azure 门户并打开活动日志时,我能够看到与 RBAC 更改、日志名称相关的日志——>“删除角色分配”、“创建角色分配”。我正在使用字符串“Microsoft.Compute”测试提到的命令:

Get-AzureRmLog -StartTime (Get-Date).AddDays(-10) | 
Where-Object {$_.Authorization.Action -like 
""*Microsoft.Compute/*""}

Get-AzureRmLog -StartTime 2019-09-01T10:30 | Where-Object {$_.Authorization.Action -like "*Microsoft.Compute/*"}`

我可以在输出中看到日志信息。我不确定什么是错的,我应该纠正什么。为什么我不能在我的产品订阅中使用这个过滤器——>“ Microsoft.Authorization/ ”,我想在我的测试订阅脚本中强调它工作得很好。

标签: azureazure-powershell

解决方案


如果要获取 RBAC 更改相关的日志,可以使用以下脚本获取。

Connect-AzureRmAccount

Get-AzureRmLog -ResourceProvider Microsoft.Authorization -StartTime (Get-Date).AddMonths(-1) 

在此处输入图像描述

有关详细信息,请参阅 https://docs.microsoft.com/en-us/powershell/module/azurerm.insights/get-azurermlog?view=azurermps-6.13.0

更新

如果要使用 Azure rest api 获取与 RBAC 更改相关的日志,则需要使用如下所示的rest api

Method : GET
URL:https://management.azure.com/subscriptions/<subscription id>/providers/microsoft.insights/eventtypes/management/values
Params:
       api-version = 2017-03-01-preview
       $filter = eventTimestamp ge 'your strat time' and resourceTypes eq 'microsoft.authorization/roleassignments'
Header:
       Authorization : Bearer access_token

例如: 在此处输入图像描述

根据我的测试,如果你的日志数量太大,结果会被分页。如果要获取其他页面的结果,我们需要向 nextlink 发送请求,nextlink 是结果中的一个参数。 在此处输入图像描述


推荐阅读