Freigeben über


Add/Remove users to a user role

Currently there is no cmdlet to add a user to a user role, however its very easy to do using a combination of the Get-UserRole cmdlet and a bit of the SDK.

$operatorsUserRole = Get-UserRole | where {$_.DisplayName -eq "Operations Manager Operators"}

$operatorsUserRole.Users.Add("contoso\AdOperators")

$operatorsUserRole.Update()

Removing users from a user role is very similar, just call Remove() rather than add.

$operatorsUserRole = Get-UserRole | where {$_.DisplayName -eq "Operations Manager Operators"}

$operatorsUserRole.Users.Remove("contoso\AdOperators")

$operatorsUserRole.Update()

 Dont forget to call the Update method on the user role object. Otherwise your changes will not be saved.

Comments