Disable Office 365 Services with PowerShell

Disable Office 365 Services with PowerShell

Ok, in our previous article we discussed how to connect to various service in Office 365, now we will show up how you can disable Office 365 services

Office 365 – Create a Secret Group
Disable Giphy in Microsoft Teams
Office 365 Powershell Connections

Ok, in our previous article we discussed how to connect to various service in Office 365, now we will show up how you can disable Office 365 services for some or all users using Powershell. In this instance we will only need the Azure AD Powershell Module, and be an Azure AD Administrator.

First, let’s look at the subscriptions that you have available:

$cred = Get-Credential
Connect-AzureAD -Credential $cred
Get-AzureADSubscribedSku | Format-Table -AutoSize -Wrap

This should return something similar to the below:

Azure AD Subscriptions

Next you need to get the Service Plans for the subscription that you choose, in this example I will use the “EnterPrise Pack” (second one from the top). I will use the ObjectID to get the service plans for that subscription.

Get-AzureADSubscribedSku -ObjectId 555fceb4-bfe2-40ba-ba9a-88b914509e7b_6fd2c87f-b296-42f0-b197-1e91e994b900 | Select-Object -ExpandProperty ServicePlans

Get Office 365 Subscribed Plans with PowerShell

Here you will see all the subscribed service plans within that subscription, you can take note of the Service Plan ID’s of each service that you can use later for disabling use for a user or all users.

Now, lets look at disabling a service for one user:

#Save the user to a variable.
$User = Get-AzureADUser -ObjectId jholder@thecodeasylum.com
$Sku = New-Object -TypeName Microsoft.Open.AzureAD.Model.AssignedLicense
#Provide the Subscription ID
$Sku.SkuId = "6fd2c87f-b296-42f0-b197-1e91e994b900"
#Provide the Subscription ID and Service Plan ID
$Sku.DisabledPlans = @("6fd2c87f-b296-42f0-b197-1e91e994b900", "2789c901-c14e-48ab-a76a-be334d9d793a")
$Licenses = New-Object -TypeName
Microsoft.Open.AzureAD.Model.AssignedLicenses
$Licenses.AddLicenses = $Sku
Set-AzureADUserLicense - ObjectId $User.ObjectId -AssignedLicenses $Licenses

You could apply the change to all users in a department similar to:

Get-AzureADUser | Where { $_.Department -eq "Marketing" } | Set-AzureADUserLicense -AssignedLicenses $Licenses
WARNING!
Be careful before applying changes to the whole company as all users may not be using the same license, for example standard office workers may be using E3 while Executives may be using E5.

COMMENTS

WORDPRESS: 0