使用 Office 365 PowerShell 管理用户帐户和许可证(五)Assign roles to user accounts with Office 365 PowerShell



Assign roles to user accounts with Office 365 PowerShell

 

上一次修改主题:2016-06-22

Summary: Use Office 365 PowerShell and the Add-MsolRoleMember cmdlet to assign roles to user accounts.

You can quickly and easily assign roles to user accounts using Office 365 PowerShell by identifying the user account's Display Name and the role name.

Determine the following:

  • Which user accounts that you want to configure.

    To specify the user account, you must determine its Display Name. To get a list accounts, use this command:

    Get-MsolUser | Sort DisplayName | Select-Object DisplayName | More
    

    This command lists the Display Name of your user accounts, sorted by the Display Name, one screen at a time. You can filter the list to a smaller set by using the Where cmdlet. Here is an example:

    Get-MsolUser | Where DisplayName -like "John*" | Sort DisplayName | Select-Object DisplayName | More
    

    This command lists only the user accounts for which the Display Name starts with "John".

  • Which roles you want to assign to each user account.

    To display the list of available roles that you can assign to user accounts, use this command:

    Get-MsolRole | Sort Name | Select-Object Name, Description
    

Once you have determined the Display Name of the account and the Name of the role, use these commands to assign a role to an account:

$dispName="<The Display Name of the account>"
$roleName="<The role Name you want to assign to the account>"
$userObject=Get-MsolUser | Where DisplayName -eq $dispName
$userUPN=$userObject.UserPrincipalName
Add-MsolRoleMember -RoleMemberEmailAddress  $userUPN -RoleName $roleName

Copy the commands and paste them into Notepad. For the $dispName and $roleName variables, replace the description text, remove the < and > characters, and leave the quotes. Copy the modified lines and paste them into your Windows PowerShell window to run them. Alternately, you can use the Windows PowerShell Integrated Script Environment (ISE).

Here is an example of a completed command set:

$dispName="Scott Wallace"
$roleName="SharePoint Service Administrator"
$userObject=Get-MsolUser | Where DisplayName -eq $dispName
$userUPN=$userObject.UserPrincipalName
Add-MsolRoleMember -RoleMemberEmailAddress  $userUPN -RoleName $roleName

See Add-MsolRoleMember for additional options that you can set.

For PowerShell basics, see the Microsoft PowerShell Tutorial & Training Course from Microsoft Virtual Academy. For PowerShell basics for Office 365, see Office 365 PowerShell 入门.

For additional help with this procedure, please post your question and the name of this topic in the PowerShell for Office 365 group of the Office 365 Yammer Network.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值