SOLVED

Powershell to disable Teams for all users

Brass Contributor

I want to run a powershell script to disable the Teamoption in all users licenses.

 

$license = "contoso: ENTERPRISEPACK_FACULTY"


$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $license -DisabledPlans TEAMS1


Set-MsolUserLicense -UserPrincipalName "testcase@contoso.com" -AddLicenses $license -LicenseOptions $LicenseOptions

 

Then I get an error:

Set-MsolUserLicense : Unable to assign this license because it is invalid.

 

What am I doing wrong?

12 Replies
Remove "-AddLicenses $license" and check.

Set-MsolUserLicense -UserPrincipalName "testcase@contoso.com" -LicenseOptions $LicenseOptions
To disable TEAMS for all users, you can try the below script

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $license -DisabledPlans TEAMS1

$AllLicensed = Get-MsolUser -All | where {$_.isLicensed -eq $true}; $AllLicensed | foreach {Set-MsolUserLicense -LicenseOptions $LicenseOptions }

That is working, great.

The script for all users is asking me an input:

cmdlet Set-MsolUserLicense at command pipeline position 1
Supply values for the following parameters:
ObjectId:

What is wrong here?

Did you try something like the following already?

 

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $license -DisabledPlans TEAMS1

$AllLicensed = Get-MsolUser -All | where {$_.isLicensed -eq $true};

$AllLicensed | foreach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LicenseOptions }

 

Where "tenant" is the name of your tenant.

Sorry, the objectid was missing, please check the below updated script.

 

$LicenseOptions = New-MsolLicenseOptions -AccountSkuId $license -DisabledPlans TEAMS1

$AllLicensed = Get-MsolUser -All | where {$_.isLicensed -eq $true};$AllLicensed | foreach {Set-MsolUserLicense -ObjectId $_.ObjectId -LicenseOptions $LicenseOptions }

Same result:

Set-MsolUserLicense : Unable to assign this license because the license options
are invalid.
At line:1 char:25

Also same result:
Set-MsolUserLicense : Unable to assign this license because the license options
are invalid.
At line:1 char:92
best response confirmed by VI_Migration (Silver Contributor)
Solution
It seems the license that you already applied to the user and the one we are trying to apply now are different, due to this error is thrown. You can also use the below tool from Microsoft TechNet Gallery.

https://gallery.technet.microsoft.com/Office365-License-cfd9489c

Once you open the tool,
select all user -->right click-->manage License-->remove license or plan -->expand your license and select teams1 --> click update

Instead of using PowerShell, you may want to start using Group Based Licensing in Azure AD, see https://docs.microsoft.com/en-us/azure/active-directory/active-directory-licensing-group-assignment-...

Thanx, this tool is great and solved my problem.

This tool is amazing. Microsoft should take note. @Lana OBrien

1 best response

Accepted Solutions
best response confirmed by VI_Migration (Silver Contributor)
Solution
It seems the license that you already applied to the user and the one we are trying to apply now are different, due to this error is thrown. You can also use the below tool from Microsoft TechNet Gallery.

https://gallery.technet.microsoft.com/Office365-License-cfd9489c

Once you open the tool,
select all user -->right click-->manage License-->remove license or plan -->expand your license and select teams1 --> click update

View solution in original post