Skip to content

Commit dc4dcd5

Browse files
committed
Find and update in Edit conditions in multiple role assignments
1 parent c6ea95a commit dc4dcd5

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

articles/role-based-access-control/conditions-role-assignments-powershell.md

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -164,20 +164,30 @@ Condition : ((!(ActionMatches{'Microsoft.Storage/storageAccounts/blobSe
164164

165165
### Edit conditions in multiple role assignments
166166

167-
If you need to make the same update to multiple role assignments, you can use a loop. The following PowerShell commands perform the following tasks:
167+
If you need to make the same update to multiple role assignments, you can use a loop. The following commands perform the following task:
168168

169-
- Finds role assignments in a subscription with `<find-condition-string-1>` and `<find-condition-string-2>` strings in the condition.
170-
- In the condition of the found role assignments, replaces `<condition-string>` with `<replace-condition-string>`.
171-
- Updates the role assignments with the changes.
169+
- Finds role assignments in a subscription with `<find-condition-string-1>` or `<find-condition-string-2>` strings in the condition.
172170

173171
```azurepowershell
174172
$tenantId = "<your-tenant-id>"
175173
$subscriptionId = "<your-subscription-id>";
176174
$scope = "/subscriptions/$subscriptionId"
175+
$findConditionString1 = "<find-condition-string-1>"
176+
$findConditionString2 = "<find-condition-string-2>"
177177
Connect-AzAccount -TenantId $tenantId -SubscriptionId $subscriptionId
178178
$roleAssignments = Get-AzRoleAssignment -Scope $scope
179-
$foundRoleAssignments = $roleAssignments | Where-Object { ($_.Condition -Match "<find-condition-string-1>") -And ($_.Condition -Match "<find-condition-string-2>") }
180-
$updatedRoleAssignments = $foundRoleAssignments | ForEach-Object { $_.Condition = $_.Condition -replace "<condition-string>", "<replace-condition-string>"; $_ }
179+
$foundRoleAssignments = $roleAssignments | Where-Object { ($_.Condition -Match $findConditionString1) -Or ($_.Condition -Match $findConditionString2) }
180+
```
181+
182+
The following commands perform the following tasks:
183+
184+
- In the condition of the found role assignments, replaces `<condition-string>` with `<replace-condition-string>`.
185+
- Updates the role assignments with the changes.
186+
187+
```azurepowershell
188+
$conditionString = "<condition-string>"
189+
$conditionStringReplacement = "<condition-string-replacement>"
190+
$updatedRoleAssignments = $foundRoleAssignments | ForEach-Object { $_.Condition = $_.Condition -replace $conditionString, $conditionStringReplacement; $_ }
181191
$updatedRoleAssignments | ForEach-Object { Set-AzRoleAssignment -InputObject $_ -PassThru }
182192
```
183193

0 commit comments

Comments
 (0)