Troubleshooting Office 365 Licensing Issues with PowerShell

Modified on Wed, 17 Sep at 12:52 PM

Audience: Technicians & Support Engineers

Applies to: Microsoft 365 Apps (Click-to-Run), Windows 10/11


Overview

This article provides a step-by-step procedure to troubleshoot and fix Microsoft 365/Office 365 activation and licensing issues on Windows devices. Typical symptoms include “License not valid”, “Product not activated”, grace period warnings, or activation error codes (e.g., 0xC004F009, 0xC004E022).

Pre-Requisites

  • Run all PowerShell commands in an elevated (Administrator) session.
  • Verify the user has a valid Microsoft 365 Apps license assigned in the Microsoft 365 Admin Center.
  • Confirm the device has reliable Internet connectivity and system date/time are correct.

Step 1 — Locate the Office Installation (Click-to-Run)

Identify installation root, platform (x64/x86), and build:

$k1 = 'HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration'
$k2 = 'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Office\ClickToRun\Configuration'
foreach ($k in $k1,$k2) {
  if (Test-Path $k) {
    Get-ItemProperty -Path $k | Select-Object InstallRoot, Platform, ProductReleaseIds, ClientVersionToReport
  }
}

Step 2 — Find OSPP.VBS (Activation Script)

Locate the activation management script path:

$paths = @(
  "C:\Program Files\Microsoft Office\root\Office16",
  "C:\Program Files (x86)\Microsoft Office\root\Office16"
)
foreach ($p in $paths) {
  $f = Join-Path $p 'ospp.vbs'
  if (Test-Path $f) { $f }
}

Step 3 — Check Current Activation Status

Show installed licenses and their states:

cscript.exe //nologo "C:\Program Files\Microsoft Office\root\Office16\ospp.vbs" /dstatus

List all known license SKUs (trials/demos included):

cscript.exe //nologo "C:\Program Files\Microsoft Office\root\Office16\ospp.vbs" /dstatusall

Interpretation Tips:

  • Grace/Expired/Notifications states indicate invalid or stale keys that should be removed.
  • 0xC004E022 often points to a secure store mismatch (cached tokens out of sync).
  • 0xC004F014 means placeholder trial/demo entries (no key) — safe to ignore or clean up later.

Step 4 — Remove Expired or Invalid Keys

Uninstall any keys in Grace or Notifications state. Replace XXXXX with the last 5 characters of the key from /dstatus:

cscript.exe //nologo "C:\Program Files\Microsoft Office\root\Office16\ospp.vbs" /unpkey:XXXXX

Repeat for each invalid key found.

Step 5 — Reactivate the Subscription License

After removing invalid keys, trigger an activation refresh:

cscript.exe //nologo "C:\Program Files\Microsoft Office\root\Office16\ospp.vbs" /act

Expected Result: Output includes <Product activation successful> and license status changes to LICENSED.

Step 6 — Confirm Activation

Verify final state:

cscript.exe //nologo "C:\Program Files\Microsoft Office\root\Office16\ospp.vbs" /dstatus
  • LICENSE STATUS: LICENSED
  • REMAINING GRACE: ~30 days (auto-renews when user is signed into Office)

Step 7 — Validate in Office Apps

  1. Open Word or Excel.
  2. Go to File > Account.
  3. Confirm it shows Product Activated and that the correct Microsoft 365 account is signed in.

Common Error Codes (Quick Reference)

  • 0x4004F00C — In grace period; needs activation.
  • 0xC004F009 — Grace period expired; remove bad key(s) then activate.
  • 0xC004E022 — Secure store mismatch; remove stale keys and reactivate (clear tokens if needed).
  • 0xC004F014 — Placeholder trial/demo license; can usually be ignored or cleaned up.

Optional Cleanup (Trials/Demos)

After successful activation, you may remove leftover trial/demo stubs for cleanliness by repeating /unpkey:XXXXX for any unwanted entries shown by /dstatusall. This is optional and does not affect a successful activation.


Notes & Best Practices

  • Always use the Click-to-Run path: C:\Program Files\Microsoft Office\root\Office16 (or Program Files (x86) for 32-bit installs).
  • If activation keeps failing with secure store errors, sign out of Office apps, close them, and try again after removing stale keys. As a last resort, clear cached Office tokens and identities, then reactivate.
  • Ensure only the intended Microsoft 365 account is signed in under File > Account.

Change Log

  • v1.0 — Initial KB with PowerShell-based remediation steps and error code guide.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article