@@ -52,16 +52,17 @@ Now you can start using the cmdlets in the module. For a full description of the
52
52
1 . Create a new role using the following PowerShell script.
53
53
54
54
``` PowerShell
55
+ ## Assign a role to a user or service principal with resource scope
55
56
# Get the user and role definition you want to link
56
- $user = Get-AzureADMSUser -Filter "userPrincipalName eq '[email protected] '"
57
+ $user = Get-AzureADUser -Filter "userPrincipalName eq '[email protected] '"
57
58
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Application Support Administrator'"
58
59
59
60
# Get app registration and construct resource scope for assignment.
60
- "displayName eq 'f/128 Filter Photos'"
61
- $resourceScopes = '/' + $appRegistration.objectId
61
+ $appRegistration = Get-AzureADApplication -Filter "displayName eq 'f/128 Filter Photos'"
62
+ $resourceScope = '/' + $appRegistration.objectId
62
63
63
64
# Create a scoped role assignment
64
- $roleAssignment = New-AzureADMSRoleAssignment -ResourceScopes $resourceScopes -RoleDefinitionId $roleDefinition.objectId -PrincipalId $user.objectId
65
+ $roleAssignment = New-AzureADMSRoleAssignment -ResourceScope $resourceScope -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.objectId
65
66
```
66
67
67
68
To assign the role to a service principal instead of a user, use the [ Get-AzureADMSServicePrincipal cmdlet] ( https://docs.microsoft.com/powershell/module/azuread/get-azureadserviceprincipal?view=azureadps-2.0 ) .
@@ -74,24 +75,20 @@ Role definition objects contain the definition of the built-in or custom role, a
74
75
75
76
``` PowerShell
76
77
# Basic information
77
-
78
- $description = "Application Registration Credential Administrator"
79
- $displayName = "Custom Demo Admin"
80
- $resourceScopes = @('/')
81
- $templateId = "355aed8a-864b-4e2b-b225-ea95482e7570"
78
+ $description = "Can manage credentials of application registrations"
79
+ $displayName = "Application Registration Credential Administrator"
80
+ $templateId = (New-Guid).Guid
82
81
83
82
# Set of actions to grant
84
83
$allowedResourceAction =
85
84
@(
86
- "microsoft.directory/applications/default /read",
85
+ "microsoft.directory/applications/standard /read",
87
86
"microsoft.directory/applications/credentials/update"
88
87
)
89
- $resourceActions = @{'allowedResourceActions'= $allowedResourceAction}
90
- $rolePermission = @{'resourceActions' = $resourceActions}
91
- $rolePermissions = $rolePermission
88
+ $rolePermissions = @{'allowedResourceActions'= $allowedResourceAction}
92
89
93
90
# Create new custom admin role
94
- $customAdmin = New-AzureADMSRoleDefinitions -RolePermissions $rolePermissions -ResourceScopes $resourceScopes -DisplayName $displayName -Description $description -TemplateId $templateId -IsEnabled $true
91
+ $customAdmin = New-AzureADMSRoleDefinition -RolePermissions $rolePermissions -DisplayName $displayName -Description $description -TemplateId $templateId -IsEnabled $true
95
92
```
96
93
97
94
### Read Operations on RoleDefinition
@@ -101,10 +98,10 @@ $customAdmin = New-AzureADMSRoleDefinitions -RolePermissions $rolePermissions -R
101
98
Get-AzureADMSRoleDefinitions
102
99
103
100
# Get single role definition by objectId
104
- $customAdmin = Get-AzureADMSRoleDefinitions -ObjectId ' 86593cfc-114b-4a15-9954-97c3494ef49b'
101
+ Get-AzureADMSRoleDefinition -Id 86593cfc-114b-4a15-9954-97c3494ef49b
105
102
106
103
# Get single role definition by templateId
107
- $customAdmin = Get-AzureADMSRoleDefinitions -Filter "templateId eq '355aed8a-864b-4e2b-b225-ea95482e757not
104
+ Get-AzureADMSRoleDefinition -Filter "templateId eq 'c4e39bd9-1100-46d3-8c65-fb160da0071f'"
108
105
```
109
106
110
107
### Update Operations on RoleDefinition
@@ -113,14 +110,14 @@ $customAdmin = Get-AzureADMSRoleDefinitions -Filter "templateId eq '355aed8a-864
113
110
# Update role definition
114
111
# This works for any writable property on role definition. You can replace display name with other
115
112
# valid properties.
116
- Set-AzureADMSRoleDefinitions -ObjectId $customAdmin.ObjectId -DisplayName "Updated DisplayName"
113
+ Set-AzureADMSRoleDefinition -Id c4e39bd9-1100-46d3-8c65-fb160da0071f -DisplayName "Updated DisplayName"
117
114
```
118
115
119
116
### Delete operations on RoleDefinition
120
117
121
118
``` PowerShell
122
119
# Delete role definition
123
- Remove-AzureADMSRoleDefinitions -ObjectId $customAdmin.ObjectId
120
+ Remove-AzureADMSRoleDefinitions -Id c4e39bd9-1100-46d3-8c65-fb160da0071f
124
121
```
125
122
126
123
## Operations on RoleAssignment
@@ -130,32 +127,33 @@ Role assignments contain information linking a given security principal (a user
130
127
### Create Operations on RoleAssignment
131
128
132
129
``` PowerShell
133
- # Scopes to scope granted permissions to
134
- $resourceScopes = @('/')
130
+ # Get the user and role definition you want to link
131
+ $user = Get-AzureADUser -Filter "userPrincipalName eq '[email protected] '"
132
+ $roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Application Support Administrator'"
135
133
136
- # IDs of principal and role definition you want to link
137
- $principalId = "27c8ca78-ab1c-40ae-bd1b-eaeebd6f68ac "
138
- $roleDefinitionId = $customKeyCredAdmin.ObjectId
134
+ # Get app registration and construct resource scope for assignment.
135
+ $appRegistration = Get-AzureADApplication -Filter "displayName eq 'f/128 Filter Photos' "
136
+ $resourceScope = '/' + $appRegistration.objectId
139
137
140
138
# Create a scoped role assignment
141
- $roleAssignment = New-AzureADMSRoleAssignments -ResourceScopes $resourceScopes -RoleDefinitionId -PrincipalId $principalId
139
+ $roleAssignment = New-AzureADMSRoleAssignment -ResourceScope $resourceScope -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.objectId
142
140
```
143
141
144
142
### Read Operations on RoleAssignment
145
143
146
144
``` PowerShell
147
145
# Get role assignments for a given principal
148
- Get-AzureADMSRoleAssignments -Filter "principalId eq '27c8ca78-ab1c-40ae-bd1b-eaeebd6f68ac'"
146
+ Get-AzureADMSRoleAssignment -Filter "principalId eq '27c8ca78-ab1c-40ae-bd1b-eaeebd6f68ac'"
149
147
150
148
# Get role assignments for a given role definition
151
- Get-AzureADMSRoleAssignments -Filter "principalId eq '355aed8a-864b-4e2b-b225-ea95482e7570'"
149
+ Get-AzureADMSRoleAssignment -Filter "roleDefinitionId eq '355aed8a-864b-4e2b-b225-ea95482e7570'"
152
150
```
153
151
154
152
### Delete Operations on RoleAssignment
155
153
156
154
``` PowerShell
157
155
# Delete role assignment
158
- Remove-AzureADMSRoleAssignments -ObjectId $roleAssignment.ObjectId
156
+ Remove-AzureADMSRoleAssignment -Id 'qiho4WOb9UKKgng_LbPV7tvKaKRCD61PkJeKMh7Y458-1'
159
157
```
160
158
161
159
## Next steps
0 commit comments