Disable access to services with Office 365 PowerShell

Summary: Explains how to use Office 365 PowerShell to disable access to Office 365 services for users in your organization.

When an Office 365 account is assigned a license from a licensing plan, Office 365 services are made available to the user from that license. However, you can control the Office 365 services that the user can access. For example, even though the license allows access to the SharePoint Online service, you can disable access to it. You can use Office 365 PowerShell to disable access to any number of services for a specific licensing plan for:

  • An individual account.

  • A group of accounts.

  • All accounts in your organization.

Before you begin

Disable specific Office 365 services for specific users for a specific licensing plan

To disable a specific set of Office 365 services for users for a specific licensing plan, perform the following steps:

  1. Identify the undesirable services in the licensing plan by using the following syntax:
$LO = New-MsolLicenseOptions -AccountSkuId <AccountSkuId> -DisabledPlans "<UndesirableService1>", "<UndesirableService2>"...

The following example creates a LicenseOptions object that disables the Office Online and SharePoint Online services in the licensing plan named litwareinc:ENTERPRISEPACK (Office 365 Enterprise E3).

$LO = New-MsolLicenseOptions -AccountSkuId "litwareinc:ENTERPRISEPACK" -DisabledPlans "SHAREPOINTWAC", "SHAREPOINTENTERPRISE"
  1. Use the LicenseOptions object from Step 1 on one or more users.
  • To create a new account that has the services disabled, use the following syntax:
New-MsolUser -UserPrincipalName <Account> -DisplayName <DisplayName> -FirstName <FirstName> -LastName <LastName> -LicenseAssignment <AccountSkuId> -LicenseOptions $LO -UsageLocation <CountryCode>

The following example creates a new account for Allie Bellew that assigns the license and disables the services described in Step 1.

New-MsolUser -UserPrincipalName allieb@litwareinc.com -DisplayName "Allie Bellew" -FirstName Allie -LastName Bellew -LicenseAssignment litwareinc:ENTERPRISEPACK -LicenseOptions $LO -UsageLocation US

For more information about creating user accounts in Office 365 PowerShell, see Create user accounts with Office 365 PowerShell.

  • To disable the services for an existing licensed user, use the following syntax:
Set-MsolUserLicense -UserPrincipalName <Account> -LicenseOptions $LO

This example disables the services for the user BelindaN@litwareinc.com.

Set-MsolUserLicense -UserPrincipalName belindan@litwareinc.com -LicenseOptions $LO
  • To disable the services described in Step 1 for all existing licensed users, specify the name of your Office 365 plan from the display of the Get-MsolAccountSku cmdlet (such as litwareinc:ENTERPRISEPACK), and then run the following commands:
$acctSKU="<AccountSkuId>"
$AllLicensed = Get-MsolUser -All | Where {$_.isLicensed -eq $true -and $_.licenses[0].AccountSku.SkuPartNumber -eq ($acctSKU).Substring($acctSKU.IndexOf(":")+1, $acctSKU.Length-$acctSKU.IndexOf(":")-1)}
$AllLicensed | ForEach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LO}
  • To disable the services for a group of existing users, use either of the following methods to identify the users:

  • Filter the accounts based on an existing account attribute To do this, use the following syntax:

$x = Get-MsolUser -All <FilterableAttributes>
$x | ForEach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LO}

The following example disables the services for users in the Sales department in the United States.

$USSales = Get-MsolUser -All -Department "Sales" -UsageLocation "US"
$USSales | ForEach {Set-MsolUserLicense -UserPrincipalName $_.UserPrincipalName -LicenseOptions $LO}
  • Use a list of specific accounts To do this, perform the following steps:
  1. Create a text file that contains one account on each line like this:
akol@contoso.com
tjohnston@contoso.com
kakers@contoso.com

In this example, the text file is C:\My Documents\Accounts.txt.

  1. Run the following command:
Get-Content "C:\My Documents\Accounts.txt" | foreach {Set-MsolUserLicense -UserPrincipalName $_ -LicenseOptions $LO}

If you want to disable access to services for multiple licensing plans, repeat the above instructions for each licensing plan, ensuring that:

  • The user accounts have been assigned the licensing plan.
  • The services to disable are available in the licensing plan.

To disable Office 365 services for users while you are assigning them to a licensing plan, see Disable access to services while assigning user licenses.

New to Office 365?

Tip

LinkedIn logo New to Office 365?

Discover free video courses for Office 365 admins and IT pros, brought to you by LinkedIn Learning.

See also

See the following additional topics about managing users with Office 365 PowerShell:

For more information about the cmdlets that are used in these procedures, see the following topics: