Skip to content

Commit e7fb3c4

Browse files
authored
Update Example1 (#23642)
Updated the example to be easier to understand without having to read an existing role and alter it. It is easier to just create an empty role and define it.
1 parent 7188330 commit e7fb3c4

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

src/Resources/Resources/help/New-AzRoleDefinition.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -82,28 +82,26 @@ Following is a sample json role definition that can be provided as input
8282

8383
### Example 1: Create using PSRoleDefinitionObject
8484
```powershell
85-
$role = Get-AzRoleDefinition -Name "Virtual Machine Contributor"
86-
87-
$role.Id = $null
88-
$role.Name = "Virtual Machine Operator"
89-
$role.Description = "Can monitor, start, and restart virtual machines."
90-
$role.IsCustom = $True
91-
$role.Actions.RemoveRange(0,$role.Actions.Count)
92-
$role.Actions.Add("Microsoft.Compute/*/read")
93-
$role.Actions.Add("Microsoft.Compute/virtualMachines/start/action")
94-
$role.Actions.Add("Microsoft.Compute/virtualMachines/restart/action")
95-
$role.Actions.Add("Microsoft.Compute/virtualMachines/downloadRemoteDesktopConnectionFile/action")
96-
$role.Actions.Add("Microsoft.Network/*/read")
97-
$role.Actions.Add("Microsoft.Storage/*/read")
98-
$role.Actions.Add("Microsoft.Authorization/*/read")
99-
$role.Actions.Add("Microsoft.Resources/subscriptions/resourceGroups/read")
100-
$role.Actions.Add("Microsoft.Resources/subscriptions/resourceGroups/resources/read")
101-
$role.Actions.Add("Microsoft.Insights/alertRules/*")
102-
$role.Actions.Add("Microsoft.Support/*")
103-
$role.AssignableScopes.Clear()
104-
$role.AssignableScopes.Add("/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
105-
106-
New-AzRoleDefinition -Role $role
85+
$role = New-Object -TypeName Microsoft.Azure.Commands.Resources.Models.Authorization.PSRoleDefinition
86+
$role.Name = 'Virtual Machine Operator'
87+
$role.Description = 'Can monitor, start, and restart virtual machines.'
88+
$role.IsCustom = $true
89+
$role.AssignableScopes = @("/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx")
90+
$role.Actions = @(
91+
"Microsoft.Compute/*/read"
92+
"Microsoft.Compute/virtualMachines/start/action"
93+
"Microsoft.Compute/virtualMachines/restart/action"
94+
"Microsoft.Compute/virtualMachines/downloadRemoteDesktopConnectionFile/action"
95+
"Microsoft.Network/*/read"
96+
"Microsoft.Storage/*/read"
97+
"Microsoft.Authorization/*/read"
98+
"Microsoft.Resources/subscriptions/resourceGroups/read"
99+
"Microsoft.Resources/subscriptions/resourceGroups/resources/read"
100+
"Microsoft.Insights/alertRules/*"
101+
"Microsoft.Support/*"
102+
)
103+
104+
New-AzRoleDefinition -Role $role
107105
```
108106

109107
### Example 2: Create using JSON file

0 commit comments

Comments
 (0)