Skip to content

Commit 48384e4

Browse files
authored
Merge pull request #84650 from VinceSmith/patch-27
Fixing bugs in sample.
2 parents 7867275 + 70a5aa0 commit 48384e4

File tree

2 files changed

+52
-52
lines changed

2 files changed

+52
-52
lines changed

articles/active-directory/users-groups-roles/roles-assign-powershell.md

Lines changed: 25 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -52,16 +52,17 @@ Now you can start using the cmdlets in the module. For a full description of the
5252
1. Create a new role using the following PowerShell script.
5353

5454
``` PowerShell
55+
## Assign a role to a user or service principal with resource scope
5556
# 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]'"
5758
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Application Support Administrator'"
5859
5960
# 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
6263
6364
# 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
6566
```
6667

6768
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
7475

7576
``` PowerShell
7677
# 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
8281
8382
# Set of actions to grant
8483
$allowedResourceAction =
8584
@(
86-
"microsoft.directory/applications/default/read",
85+
"microsoft.directory/applications/standard/read",
8786
"microsoft.directory/applications/credentials/update"
8887
)
89-
$resourceActions = @{'allowedResourceActions'= $allowedResourceAction}
90-
$rolePermission = @{'resourceActions' = $resourceActions}
91-
$rolePermissions = $rolePermission
88+
$rolePermissions = @{'allowedResourceActions'= $allowedResourceAction}
9289
9390
# 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
9592
```
9693

9794
### Read Operations on RoleDefinition
@@ -101,10 +98,10 @@ $customAdmin = New-AzureADMSRoleDefinitions -RolePermissions $rolePermissions -R
10198
Get-AzureADMSRoleDefinitions
10299
103100
# 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
105102
106103
# 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'"
108105
```
109106

110107
### Update Operations on RoleDefinition
@@ -113,14 +110,14 @@ $customAdmin = Get-AzureADMSRoleDefinitions -Filter "templateId eq '355aed8a-864
113110
# Update role definition
114111
# This works for any writable property on role definition. You can replace display name with other
115112
# valid properties.
116-
Set-AzureADMSRoleDefinitions -ObjectId $customAdmin.ObjectId -DisplayName "Updated DisplayName"
113+
Set-AzureADMSRoleDefinition -Id c4e39bd9-1100-46d3-8c65-fb160da0071f -DisplayName "Updated DisplayName"
117114
```
118115

119116
### Delete operations on RoleDefinition
120117

121118
``` PowerShell
122119
# Delete role definition
123-
Remove-AzureADMSRoleDefinitions -ObjectId $customAdmin.ObjectId
120+
Remove-AzureADMSRoleDefinitions -Id c4e39bd9-1100-46d3-8c65-fb160da0071f
124121
```
125122

126123
## Operations on RoleAssignment
@@ -130,32 +127,33 @@ Role assignments contain information linking a given security principal (a user
130127
### Create Operations on RoleAssignment
131128

132129
``` 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'"
135133
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
139137
140138
# 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
142140
```
143141

144142
### Read Operations on RoleAssignment
145143

146144
``` PowerShell
147145
# 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'"
149147
150148
# 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'"
152150
```
153151

154152
### Delete Operations on RoleAssignment
155153

156154
``` PowerShell
157155
# Delete role assignment
158-
Remove-AzureADMSRoleAssignments -ObjectId $roleAssignment.ObjectId
156+
Remove-AzureADMSRoleAssignment -Id 'qiho4WOb9UKKgng_LbPV7tvKaKRCD61PkJeKMh7Y458-1'
159157
```
160158

161159
## Next steps

articles/active-directory/users-groups-roles/roles-create-custom.md

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -88,20 +88,18 @@ Create a new role using the following PowerShell script:
8888

8989
``` PowerShell
9090
# Basic role information
91-
$description = "Application Support Administrator"
92-
$displayName = "Can manage basic aspects of application registrations."
91+
$displayName = "Application Support Administrator
92+
$description = "Can manage basic aspects of application registrations."
9393
$templateId = (New-Guid).Guid
94-
94+
9595
# Set of permissions to grant
9696
$allowedResourceAction =
9797
@(
9898
"microsoft.directory/applications/basic/update",
9999
"microsoft.directory/applications/credentials/update"
100100
)
101-
$resourceActions = @{'allowedResourceActions'= $allowedResourceAction}
102-
$rolePermission = @{'resourceActions' = $resourceActions}
103-
$rolePermissions = $rolePermission
104-
101+
$rolePermissions = @{'allowedResourceActions'= $allowedResourceAction}
102+
105103
# Create new custom admin role
106104
$customAdmin = New-AzureADMSRoleDefinition -RolePermissions $rolePermissions -DisplayName $displayName -Description $description -TemplateId $templateId -IsEnabled $true
107105
```
@@ -113,14 +111,14 @@ Assign the role using the below PowerShell script:
113111
``` PowerShell
114112
# Get the user and role definition you want to link
115113
$user = Get-AzureADUser -Filter "userPrincipalName eq '[email protected]'"
116-
$roleDefinition = Get-AzureADRoleDefinition -Filter "displayName eq ' Application Registration Creator'"
114+
$roleDefinition = Get-AzureADMSRoleDefinition -Filter "displayName eq 'Application Support Administrator'"
117115
118116
# Get app registration and construct resource scope for assignment.
119117
$appRegistration = Get-AzureADApplication -Filter "displayName eq 'f/128 Filter Photos'"
120-
$resourceScopes = '/' + $appRegistration.objectId
118+
$resourceScope = '/' + $appRegistration.objectId
121119
122120
# Create a scoped role assignment
123-
$roleAssignment = New-AzureADRoleAssignment -ResourceScopes $resourceScopes -RoleDefinitionId $roleDefinition.objectId -PrincipalId $user.objectId
121+
$roleAssignment = New-AzureADMSRoleAssignment -ResourceScope $resourceScope -RoleDefinitionId $roleDefinition.Id -PrincipalId $user.objectId
124122
```
125123

126124
## Create a custom role using Microsoft Graph API
@@ -138,16 +136,20 @@ $roleAssignment = New-AzureADRoleAssignment -ResourceScopes $resourceScopes -Rol
138136
Body
139137
140138
``` HTTP
141-
{
142-
"description":"Can manage basic aspects of application registrations.",
143-
"displayName":"Application Support Administrator",
144-
"isEnabled":true,
145-
"rolePermissions":
146-
[
147-
"microsoft.directory/applications/basic/update",
148-
"microsoft.directory/applications/credentials/update"
149-
]
150-
}
139+
{
140+
"description": "Can manage basic aspects of application registrations.",
141+
"displayName": "Application Support Administrator",
142+
"isEnabled": true,
143+
"templateId": "<GUID>",
144+
"rolePermissions": [
145+
{
146+
"allowedResourceActions": [
147+
"microsoft.directory/applications/basic/update",
148+
"microsoft.directory/applications/credentials/update"
149+
]
150+
}
151+
]
152+
}
151153
```
152154
153155
1. Create the role assignment.
@@ -163,11 +165,11 @@ $roleAssignment = New-AzureADRoleAssignment -ResourceScopes $resourceScopes -Rol
163165
Body
164166
165167
``` HTTP
166-
{
167-
"principalId":"<GUID OF USER>",
168-
"roleDefinitionId":"<GUID OF ROLE DEFINITION>",
169-
"resourceScope":["/<GUID OF APPLICATION REGISTRATION>"]
170-
}
168+
{
169+
"principalId":"<GUID OF USER>",
170+
"roleDefinitionId":"<GUID OF ROLE DEFINITION>",
171+
"resourceScope":"/<GUID OF APPLICATION REGISTRATION>"
172+
}
171173
```
172174
173175
## Next steps

0 commit comments

Comments
 (0)