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
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:
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
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
COMMENTS