|
| 1 | +--- |
| 2 | +ms.service: azure-policy |
| 3 | +ms.topic: include |
| 4 | +ms.date: 06/04/2024 |
| 5 | +author: davidsmatlak |
| 6 | +ms.author: davidsmatlak |
| 7 | +--- |
| 8 | + |
| 9 | +### Policy exemptions per assignment |
| 10 | + |
| 11 | +Lists the number of exemptions for each assignment. |
| 12 | + |
| 13 | +```kusto |
| 14 | +PolicyResources |
| 15 | +| where type == 'microsoft.authorization/policyexemptions' |
| 16 | +| summarize count() by tostring(properties.policyAssignmentId) |
| 17 | +``` |
| 18 | + |
| 19 | +For more information about using scopes with Azure CLI or Azure PowerShell, go to [Count Azure resources](../../../../resource-graph/samples/starter.md#count-azure-resources). |
| 20 | + |
| 21 | +# [Azure CLI](#tab/azure-cli) |
| 22 | + |
| 23 | +Use the `--management-groups` parameter with an Azure management group ID or tenant ID. In this example, the `tenantid` variable stores the tenant ID. |
| 24 | + |
| 25 | +```azurecli-interactive |
| 26 | +tenantid="$(az account show --query tenantId --output tsv)" |
| 27 | +az graph query -q "policyresources | where type == 'microsoft.authorization/policyexemptions' | summarize count() by tostring(properties.policyAssignmentId)" --management-groups $tenantid |
| 28 | +``` |
| 29 | + |
| 30 | +# [Azure PowerShell](#tab/azure-powershell) |
| 31 | + |
| 32 | +By default, PowerShell get results for all subscriptions in your tenant but you can also include the `-UseTenantScope` parameter. |
| 33 | + |
| 34 | +```azurepowershell-interactive |
| 35 | +Search-AzGraph -Query "policyresources | where type == 'microsoft.authorization/policyexemptions' | summarize count() by tostring(properties.policyAssignmentId)" -UseTenantScope |
| 36 | +``` |
| 37 | + |
| 38 | +# [Portal](#tab/azure-portal) |
| 39 | + |
| 40 | +- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/policyresources%0D%0A%7C%20where%20type%20%3D%3D%20%27microsoft.authorization%2Fpolicyexemptions%27%0D%0A%7C%20summarize%20count%28%29%20by%20tostring%28properties.policyAssignmentId%29" target="_blank">portal.azure.com</a> |
| 41 | +- Azure Government portal: <a href="https://portal.azure.us/#blade/HubsExtension/ArgQueryBlade/query/policyresources%0D%0A%7C%20where%20type%20%3D%3D%20%27microsoft.authorization%2Fpolicyexemptions%27%0D%0A%7C%20summarize%20count%28%29%20by%20tostring%28properties.policyAssignmentId%29" target="_blank">portal.azure.us</a> |
| 42 | +- Microsoft Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/#blade/HubsExtension/ArgQueryBlade/query/policyresources%0D%0A%7C%20where%20type%20%3D%3D%20%27microsoft.authorization%2Fpolicyexemptions%27%0D%0A%7C%20summarize%20count%28%29%20by%20tostring%28properties.policyAssignmentId%29" target="_blank">portal.azure.cn</a> |
| 43 | + |
| 44 | +--- |
| 45 | + |
| 46 | +### Policy exemptions that expire within 90 days |
| 47 | + |
| 48 | +Lists the name and expiration date. |
| 49 | + |
| 50 | +```kusto |
| 51 | +PolicyResources |
| 52 | +| where type == 'microsoft.authorization/policyexemptions' |
| 53 | +| extend expiresOnC = todatetime(properties.expiresOn) |
| 54 | +| where isnotnull(expiresOnC) |
| 55 | +| where expiresOnC >= now() and expiresOnC < now(+90d) |
| 56 | +| project name, expiresOnC |
| 57 | +``` |
| 58 | + |
| 59 | +# [Azure CLI](#tab/azure-cli) |
| 60 | + |
| 61 | +```azurecli-interactive |
| 62 | +az graph query -q "policyresources | where type == 'microsoft.authorization/policyexemptions' | extend expiresOnC = todatetime(properties.expiresOn) | where isnotnull(expiresOnC) | where expiresOnC >= now() and expiresOnC < now(+90d) | project name, expiresOnC" |
| 63 | +``` |
| 64 | + |
| 65 | +# [Azure PowerShell](#tab/azure-powershell) |
| 66 | + |
| 67 | +```azurepowershell-interactive |
| 68 | +Search-AzGraph -Query "policyresources | where type == 'microsoft.authorization/policyexemptions' | extend expiresOnC = todatetime(properties.expiresOn) | where isnotnull(expiresOnC) | where expiresOnC >= now() and expiresOnC < now(+90d) | project name, expiresOnC" |
| 69 | +``` |
| 70 | + |
| 71 | +# [Portal](#tab/azure-portal) |
| 72 | + |
| 73 | +- Azure portal: <a href="https://portal.azure.com/#blade/HubsExtension/ArgQueryBlade/query/policyresources%0D%0A%7C%20where%20type%20%3D%3D%20%27microsoft.authorization%2Fpolicyexemptions%27%0D%0A%7C%20extend%20expiresOnC%20%3D%20todatetime%28properties.expiresOn%29%0D%0A%7C%20where%20isnotnull%28expiresOnC%29%0D%0A%7C%20where%20expiresOnC%20%3E%3D%20now%28%29%20and%20expiresOnC%20%3C%20now%28%2B90d%29%0D%0A%7C%20project%20name%2C%20expiresOnC" target="_blank">portal.azure.com</a> |
| 74 | +- Azure Government portal: <a href="https://portal.azure.us/#blade/HubsExtension/ArgQueryBlade/query/policyresources%0D%0A%7C%20where%20type%20%3D%3D%20%27microsoft.authorization%2Fpolicyexemptions%27%0D%0A%7C%20extend%20expiresOnC%20%3D%20todatetime%28properties.expiresOn%29%0D%0A%7C%20where%20isnotnull%28expiresOnC%29%0D%0A%7C%20where%20expiresOnC%20%3E%3D%20now%28%29%20and%20expiresOnC%20%3C%20now%28%2B90d%29%0D%0A%7C%20project%20name%2C%20expiresOnC" target="_blank">portal.azure.us</a> |
| 75 | +- Microsoft Azure operated by 21Vianet portal: <a href="https://portal.azure.cn/#blade/HubsExtension/ArgQueryBlade/query/policyresources%0D%0A%7C%20where%20type%20%3D%3D%20%27microsoft.authorization%2Fpolicyexemptions%27%0D%0A%7C%20extend%20expiresOnC%20%3D%20todatetime%28properties.expiresOn%29%0D%0A%7C%20where%20isnotnull%28expiresOnC%29%0D%0A%7C%20where%20expiresOnC%20%3E%3D%20now%28%29%20and%20expiresOnC%20%3C%20now%28%2B90d%29%0D%0A%7C%20project%20name%2C%20expiresOnC" target="_blank">portal.azure.cn</a> |
| 76 | + |
| 77 | +--- |
0 commit comments