Skip to content

Commit f44292b

Browse files
committed
cli intitiatives
1 parent 449b41a commit f44292b

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

articles/azure-monitor/essentials/diagnostics-settings-policies-deployifnotexists.md

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ Initiatives are collections of policies. There are three initiatives for Azure M
177177

178178
In this example, we assign an initiative for sending audit logs to a Log Analytics workspace.
179179

180-
### [Azure portal](#tab/portal1)
180+
### [Azure portal](#tab/portal)
181181

182182
1. From the policy **Definitions** page, select your scope.
183183

@@ -211,7 +211,7 @@ Change the default name in the **Parameters** tab of the **Assign initiative** o
211211

212212
:::image type="content" source="./media/diagnostics-settings-policies-deployifnotexists/edit-initiative-assignment.png" alt-text="A screenshot showing the edit-initiative-assignment page with the checkbox unselected.":::
213213

214-
### [PowerShell](#tab/Powershell1)
214+
### [PowerShell](#tab/Powershell)
215215

216216

217217
1. Set up your environment variables
@@ -267,10 +267,27 @@ You can get your policy assignment details using the following command:
267267
$policyAssignment=Get-AzPolicyAssignment -Name $assignmentName -Scope "/subscriptions/$subscriptionId/resourcegroups/$($rg.ResourceGroupName)";
268268
```
269269

270-
---
270+
### [CLI](#tab/cli)
271+
272+
Log in to your Azure account using the `az login` command.
273+
Select the subscription where you want to apply the policy initiative using the `az account` set command.
271274

275+
az policy assignment create --name <my-policy-assignment> --policy my-policy-initiative --scope /subscriptions/<subscription-id>
272276

277+
Assign the initiative.
273278

279+
```azurecli
280+
az policy assignment create --name <assignment name> --resource-group <resource group name> --policy-set-definition <initiative name> --params <parameters object> --mi-system-assigned --location <location>
281+
```
282+
for example:
283+
```azurecli
284+
az policy assignment create --name "my assignment" --resource-group "rg-001" --policy-set-definition 'f5b29bc4-feca-4cc6-a58a-772dd5e290a5' --params '{"logAnalytics":{"value":"/subscriptions/12345678-aaaa-bbbb-cccc-1234567890ab/resourceGroups/rg001/providers/microsoft.operationalinsights/workspaces/rg-001-workspace"}, "diagnosticSettingName":{"value":"AssignedByMyAssignment"}}' --mi-system-assigned --location eastus
285+
```
286+
Remediate the resources
287+
you can find the definition-reference-id in the initiative definition.
288+
az policy remediation create -g "ed-cli-initiative-01" --policy-assignment ed-cli-assignment-03 --name "rem-ed-cli-assignment-03" --definition-reference-id "keyvault-vaults" --resource-discovery-mode ReEvaluateCompliance
289+
290+
---
274291

275292

276293
## Common parameters

0 commit comments

Comments
 (0)