Offboard a User: Disable Account and Remove M365 Licenses

Prev Next

Block sign-in and reclaim licenses for a departing employee using Microsoft Graph.

Complexity: Beginner. Impact: security + cost-savings + offboarding + compliance.

Why use this workflow

When an employee leaves the organization or changes roles, two of the most time-sensitive offboarding actions are blocking sign-in and reclaiming their assigned licenses. Disabling the account revokes interactive access to Microsoft 365 services, while removing the license frees up a paid seat that you can reassign to another user.

This workflow covers the minimal, safe offboarding path: locate the user, audit their current licenses, disable the account, and remove all assigned SKUs. The user object itself is retained so that mailbox content, OneDrive files, and audit history remain accessible for any later retrieval or legal hold.

Run this as soon as HR confirms a termination or last working day. For a full offboarding workflow (mailbox conversion to shared, OneDrive handoff, group cleanup, MFA method revocation), chain this workflow with related offboarding workflows.

Expected outcomes

  • The target user's accountEnabled flag is set to false, which blocks sign-ins.
  • All Microsoft 365 SKUs assigned directly to the user are removed, returning seats to the available pool.
  • The user object, mailbox, and OneDrive remain intact for data retention and retrieval.
  • An auditable record of the disable and license removal actions is written to the Entra audit log.

Risks and considerations

Before you run this

  • Do not delete the user. Deletion eventually purges the mailbox and OneDrive. Disabling the account and removing licenses is reversible and preserves data.
  • Group-based licenses. If the user's license was assigned through a group (not directly), removing it with assignLicense fails. Remove the user from the licensing group instead.
  • Shared mailbox conversion. Removing an Exchange license eventually deletes the mailbox. If you need to retain email access for a manager, convert the mailbox to a shared mailbox before you remove the license, or place the mailbox on Litigation Hold.
  • Active sessions. Disabling the account does not immediately end existing OAuth tokens. Run revokeSignInSessions as a follow-up to force re-authentication.
  • OneDrive retention. OneDrive content is retained for a limited period after license removal unless you transfer ownership or extend retention in the SharePoint admin center. Check your tenant's retention settings.

Required permissions

PermissionWhy it's needed
User.ReadWrite.AllRequired to PATCH the user object and set accountEnabled=false.
Directory.ReadWrite.AllRequired to call assignLicense and remove SKUs from the user.
Organization.Read.AllUseful to resolve skuPartNumber to skuId when you script against multiple tenants.
User.Read.AllRequired to resolve the user by UPN or display name before you make changes.

Ask Dex

Paste the prompt into a Dex conversation.

Prompt for IT admins

Offboard {user}: disable their account to block sign-in and remove all assigned Microsoft 365 licenses. Leave the user object intact so mailbox and OneDrive data are retained, and revoke any active sessions.

Manual steps (admin center)

  1. Sign in to the Microsoft 365 admin center as a User Administrator or Global Administrator.
  2. Go to Users > Active users.
  3. Search for the departing employee by name or UPN (for example {user_upn}) and select the row to open the user pane.
  4. On the Account tab, select Block sign-in. In the dialog, select Block this user from signing in and select Save changes. This sets accountEnabled to false.
  5. (Recommended) Still on the Account tab, select Sign out of all sessions to revoke active refresh tokens.
  6. Switch to the Licenses and apps tab.
  7. Clear every assigned license (for example Microsoft 365 Business Premium). If a license is greyed out, it is inherited from a group. Remove the user from that group under Groups > Active groups instead.
  8. Select Save changes.
  9. Verify: reopen the user, confirm the banner reads Sign-in blocked, and confirm the Licenses tab shows No licenses assigned.

Optional follow-ups

  • Convert the mailbox to Shared under Exchange admin center > Recipients > Mailboxes before the license is removed.
  • Transfer OneDrive ownership to the user's manager under SharePoint admin center > More features > User profiles.

Microsoft Graph API

This is a sequence of calls: resolve the user, audit licenses, disable the account, and remove all license SKUs. All endpoints are on https://graph.microsoft.com.

1. Resolve the user

GET /v1.0/users?$filter=userPrincipalName eq '{user_upn}'&$select=id,displayName,userPrincipalName,accountEnabled

Example response:

{
  "value": [{
    "id": "6ec10ce2-e41b-46cb-bda2-2900a8965720",
    "displayName": "Alex Example",
    "userPrincipalName": "alex@contoso.com",
    "accountEnabled": true
  }]
}

2. Audit current licenses

GET /v1.0/users/{user_id}/licenseDetails?$select=skuId,skuPartNumber

Capture the skuId values. You pass them into the remove call in step 4.

3. Disable the account

PATCH /v1.0/users/{user_id}
Content-Type: application/json

{ "accountEnabled": false }

Expected response: 204 No Content.

4. Remove all licenses

POST /v1.0/users/{user_id}/assignLicense
Content-Type: application/json

{
  "addLicenses": [],
  "removeLicenses": ["{sku_id}"]
}

Expected response: 200 OK with the updated user object.

POST /v1.0/users/{user_id}/revokeSignInSessions

Returns { "value": true }. Issued refresh tokens are invalidated.

Common errors

CodeCauseFix
400 BadRequest on assignLicenseLicense is inherited from a groupRemove the user from the licensing group instead
403 ForbiddenMissing Directory.ReadWrite.AllGrant admin consent in Entra
404 NotFoundUser already deletedCheck the Deleted users view

PowerShell

Use the Microsoft Graph PowerShell SDK (Microsoft.Graph). Install it once with Install-Module Microsoft.Graph -Scope CurrentUser.

Connect with the right scopes

Connect-MgGraph -Scopes "User.ReadWrite.All", "Directory.ReadWrite.All", "Organization.Read.All"

Resolve and inspect the user

$upn = "alex@contoso.com"
$user = Get-MgUser -UserId $upn -Property Id,DisplayName,AccountEnabled,AssignedLicenses
$user | Format-List

Disable the account

Update-MgUser -UserId $user.Id -AccountEnabled:$false

Remove all licenses

$skuIds = $user.AssignedLicenses.SkuId
Set-MgUserLicense -UserId $user.Id -AddLicenses @() -RemoveLicenses $skuIds

Revoke sessions

Revoke-MgUserSignInSession -UserId $user.Id