Script to remove specific office 365 service plan
- Sep 26, 2020
- 2 min read

This script can be used in scenarios wherein you want to remove the specific office 365 service plan for a set of users or all users using CSV file depending upon the business needs.
Firstly to check all available service plan in your tenant use below mentioned steps:
Open PowerShell as an administrator and run below commands.
Import Msonline module using below command and it can be ignored if module already exist.
Install-Module Msonline
3. Connect to MsolService using below command:
Connect-MsolService
4. Run below command to check for available plan in office365 tenant:
Get-MsolAccountSku
Output will be like as shown below:

Now to remove the service plan for a set of users, use below mentioned steps:
In our case we will disable the My Analytics plan for a set of users mentioned in CSV file.
Create a CSV file like one shown below which includes Username of users for who My Analytics plan need to be disabled:

Script to remove the My Analytics service plan is as below:
Import-Module MSonline
Connect-MSOLservice
#Replace your tenant's AccountSkuId in below line which can be fetched through Get-MsolAccountSku command:
$LO = New-MsolLicenseOptions -AccountSkuId "domainname:ENTERPRISEPACK" -DisabledPlans "MYANALYTICS_P2"
#To remove the service for all the user in CSV
Import-Csv C:\files\Users.csv | foreach-object { Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LO }
After running above script, you can check the status for users using below command:
Get-MsolUser -UserPrincipalName "User email address" | select -ExpandProperty licenses | select -ExpandProperty servicestatus
Output will be like as shown below:

You can also verify the changes via GUI through Office admin center -> Active Users -> Select any user mentioned in CSV file -> Select Licenses and Apps -> Expand Apps and look for "Insights by My Analytics" license option and it should be disabled after running above script as shown in below screenshot for reference.

Reference links:
Thank you for visiting the blog, Please do share your feedback if you liked it so that I can come up with more such blogs for community.
Because "Sharing is Caring"...!!



Comments