@@ -164,20 +164,30 @@ Condition : ((!(ActionMatches{'Microsoft.Storage/storageAccounts/blobSe
164
164
165
165
### Edit conditions in multiple role assignments
166
166
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 :
168
168
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.
172
170
173
171
``` azurepowershell
174
172
$tenantId = "<your-tenant-id>"
175
173
$subscriptionId = "<your-subscription-id>";
176
174
$scope = "/subscriptions/$subscriptionId"
175
+ $findConditionString1 = "<find-condition-string-1>"
176
+ $findConditionString2 = "<find-condition-string-2>"
177
177
Connect-AzAccount -TenantId $tenantId -SubscriptionId $subscriptionId
178
178
$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; $_ }
181
191
$updatedRoleAssignments | ForEach-Object { Set-AzRoleAssignment -InputObject $_ -PassThru }
182
192
```
183
193
0 commit comments