Office365批量分配许可(License)


  1. function Connect-MSService(){  
  2.     Import-Module MsOnline  
  3.     $cred=Get-Credential -Credential xxx@xxxx.com  
  4.     Connect-MsolService -Credential $cred #-errorAction silentlyContinue -errorvariable er  
  5.     $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://partner.outlook.cn/PowerShell-LiveID -Credential $cred -Authentication Basic -AllowRedirection  
  6.     Import-PSSession $Session  
  7. }  
  8. Connect-MSService  
  9. $msolUsers = Get-MsolUser -All -Synchronized  
  10. $mailboxUsers = Get-Mailbox -ResultSize unlimited|%{$_.UserPrincipalName}  
  11.   
  12. ## Define License Options  
  13. ## There are five Services SHAREPOINTWAC,SHAREPOINTENTERPRISE,MCOSTANDARD,OFFICESUBSCRIPTION,EXCHANGE_S_ENTERPRISE in E3 Licence  
  14. ## If you want to disable any of them in the licence options, just use -DisablePlans and follow the name of the services you want to disable  
  15. $O365E3 = New-MsolLicenseOptions -AccountSkuId syndication-account:ENTERPRISEPACK_NO_RMS  
  16. $O365E3_OnlyExchange = New-MsolLicenseOptions -AccountSkuId syndication-account:ENTERPRISEPACK_NO_RMS -DisabledPlans SHAREPOINTWAC,SHAREPOINTENTERPRISE,MCOSTANDARD,OFFICESUBSCRIPTION  
  17.   
  18. ## Process each user in the collection, if they have license already, change the license options, if not, add the License with options  
  19. foreach ($msolUser in $msolUsers) {  
  20.     $HasLicense = $msolUser.IsLicensed  
  21.     if ($HasLicense) {  
  22.         #Write-Host $msolUser.UserPrincipalName -ForegroundColor Green  
  23.         #$msolUser | Set-MsolUserLicense -LicenseOptions $O365E3_OnlyExchange  
  24.     }  
  25.     else {  
  26.         if($mailboxUsers -contains $msolUser.UserPrincipalName){  
  27.             $msolUser | Set-MsolUser -UsageLocation "CN"  
  28.             $msolUser | Set-MsolUserLicense -AddLicenses "syndication-account:ENTERPRISEPACK_NO_RMS" -LicenseOptions $O365E3_OnlyExchange -ErrorAction Continue  
  29.             if($?){  
  30.                 $msolUser.IsLicensed=$true  
  31.             }else{  
  32.                 Write-Host $msolUser.UserPrincipalName -ForegroundColor green  
  33.             }  
  34.         }  
  35.     }  
  36. }  
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值