O365 - Powershell Plan许可

时间:2017-10-05 16:24:19

标签: powershell office365

我正在尝试许可已经分配了许可证的用户。例如,我为学生分配了Office 365 A1,为学生分配了Office 365 ProPlus。在这些学生中,学生只被分配到Yammer,Office Online for Education和SharePoint Plan 1 for EDU。我还需要将Exchange Online(计划1)分配给现有学生。但是,当我运行以下脚本时,我收到错误: Set-MsolUserLicense:无法分配此许可证,因为它无效。使用Get-MsolAccountSku cmdlet检索有效许可证列表。

$Username = "somecompany@microsoft.com" 
$Password = ConvertTo-SecureString "SomePassword" -AsPlainText -Force
$cred = New-Object System.Management.Automation.PSCredential $Username, 
$Password  

Connect-MsolService -Credential $cred

$StudentUsers = Get-Content -Path "pathfile\users.txt"

Foreach ($user in $StudentUsers){
$LogPath = "logpath\$user.log"

$AccountSkuIdStandard = “CORRECT_SUBSCRIBTION"

$ExchangeOnlineSku = New-MsolLicenseOptions -AccountSkuId    
$AccountSkuIdStandard -DisabledPlans AAD_BASIC_EDU, SCHOOL_DATA_SYNC_P1, 
STREAM_O365_E3, TEAMS1,Deskless, FLOW_O365_P2, POWERAPPS_O365_P2, 
RMS_S_ENTERPRISE, OFFICE_FORMS_PLAN_2,PROJECTWORKMANAGEMENT,SWAY,MCOSTANDARD

#Applies standard license disabling plans
Set-MsolUserLicense -UserPrincipalName $user -AddLicenses 
$AccountSkuIdStandard -LicenseOptions $ExchangeOnlineSku


Add-Content -Path $LogPath "$timestamp Attempting to license $user for O365 
Exchange Online for Students"

Write-Output "Pausing script...."
Start-Sleep 3

Add-Content -Path $LogPath "$user has been licensed for O365 Exchange Online 
for Students"
}

我的理解是因为已经为用户分配了许可证,因此无法为他们分配另一个许可证 当用户已经拥有许可证时,有没有办法分配计划(Exchange Online(计划1))? 我有超过10k用户需要将此计划/许可分配给。

感谢您的帮助:)

1 个答案:

答案 0 :(得分:-1)

您需要添加要删除的许可证的变量。我想这会做到。

Set-MsolUserLicense -UserPrincipalName $user -AddLicenses 
$AccountSkuIdStandard -LicenseOptions $ExchangeOnlineSku -RemoveLicenses $oldLicense

https://blogs.technet.microsoft.com/cloudpfe/2014/01/30/how-to-change-office-365-licenses-in-bulk-respecting-the-license-options/