Office365批量分配许可(License)

来源:互联网 发布:国产女装品牌知乎 编辑:程序博客网 时间:2024/04/30 16:14

[php] view plain copy print?在CODE上查看代码片派生到我的代码片
  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 0