Hi.
We are working on getting the script found at how-to-change-office-365-licenses-in-bulk-respecting-the-license-options
to work for our needs.
When we initialy ran the script nothing happened, but after some editing
we have gotten the script to work using the line: Get-MsolUser -Title "teacher" -SearchString "specific user" -MaxResults 5000 | Where-Object { $.isLicensed -eq "TRUE" } instead of the
Get-MsolUser -UserPrincipalName $member -MaxResults 5000 | Where-Object { $.isLicensed -eq "TRUE" } line
while commenting out every other line concerning $groupMember and $users
What we are trying to do is to have all users belonging to a spesific Office 365 Unified Group change license from a type of office license to another type of office license. The license name in the code is only for testing. When everything works we are going to change from Office 365 A1 license to Office 365 A3 license for students for all users belonging
to spesific Office 365 Unified Groups.
Is there a way to get this script to work with a little editing or is there some powershell commands with Get-UnifiedGroup that can be used in this script?
Here is a copy of our edited script:
------------------------------------------------------------------------------
Copyright © 2013 Microsoft Corporation. All rights reserved.
WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS
FOR A PARTICULAR PURPOSE. THE ENTIRE RISK OF USE, INABILITY TO USE, OR
RESULTS FROM THE USE OF THIS CODE REMAINS WITH THE USER.
------------------------------------------------------------------------------
Edited at later time by local user
------------------------------------------------------------------------------
Import-Module MSOnline
$cred = Get-Credential
Connect-MSOlService #-Credential $cred
$oldLicense = "OURCompany:VISIOCLIENT_FACULTY"
$newLicense = "OURcompany:ENTERPRISEPACKPLUS_STUUSEBNFT"
$groupObject = "91886745-02e2-4765-a122-8b5de26c2a95"
$groupMember = Get-MsOlGroupMember -GroupObjectId $groupObject -MaxResults 50 #getting all members from a specific group
$users = foreach ($member in $groupMember){
Get-MsolUser -UserPrincipalName $member -MaxResults 5000 | Where-Object { $_.isLicensed -eq "TRUE" } #here we are trying to extract the different members from the spesific group
}
foreach ($user in $users){
$upn = $user.UserPrincipalName #the script is using UserPrincipleName from the user variable to set witch user to change license on
foreach ($license in $user.Licenses) {
if ($license.AccountSkuId -eq $oldLicense) {
$disabledPlans = @()
foreach ($licenseStatus in $license.ServiceStatus) {
$plan = $licenseStatus.ServicePlan.ServiceName
$status = $licenseStatus.ProvisioningStatus
if ($status -eq "Disabled") {
if ($plan -eq "EXCHANGE_S_STANDARD") {
$disabledPlans += "EXCHANGE_S_ENTERPRISE"
} elseif ($plan -eq "SHAREPOINTSTANDARD") {
$disabledPlans += "SHAREPOINTWAC"
$disabledPlans += "SHAREPOINTENTERPRISE"
} else {
# Example: MCOSTANDARD
$disabledPlans += $plan
}
}
}
# Always disabled Office 365 Pro Plus.
$disabledPlans += "OFFICESUBSCRIPTION"
#$disabledPlans += "RMS_S_ENTERPRISE"
#$disabledPlans += "YAMMER_ENTERPRISE"
$disabledPlans = $disabledPlans | select -Unique
if ($disabledPlans.Length -eq 0) {
Write-Host("User $upn will go from $oldLicense to $newLicense and will have no options disabled.")
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $newLicense -RemoveLicenses $oldLicense
} else {
$options = New-MsolLicenseOptions -AccountSkuId $newLicense -DisabledPlans $disabledPlans
Write-Host("User $upn will go from $oldLicense to $newLicense and will have these options disabled: $disabledPlans")
Set-MsolUserLicense -UserPrincipalName $upn -AddLicenses $newLicense -LicenseOptions $options -RemoveLicenses $oldLicense
}
}
}
}