When Office products show "Unlicensed" or activate with the wrong account/key after migration, you might need to remove a specific, problematic license key directly from the command line.

The Fix

# For Office 2016/2019/2021/365
cd "C:\Program Files\Microsoft Office\Office16\"

# For Office 2013
# cd "C:\Program Files\Microsoft Office\Office15\"

# List installed product keys
cscript ospp.vbs /dstatus

# Note the <Last 5 characters of installed product key> you want to remove
cscript ospp.vbs /unpkey:<Last5Char>

Why it works

  • The ospp.vbs script is the Office Software Protection Platform script. /dstatus lists all installed licenses, and /unpkey: removes the specified product key from the system.

Verify

  • After removing the key, reopen any Office application (e.g., Word). It should prompt you to sign in with an account or enter a new product key, indicating the old problematic license is gone.

Notes

  • Requires Administrator privileges.
  • Adjust the cd command to the correct Office installation directory for your version.
  • Be careful to select the correct 5 characters for the key you wish to remove, especially if multiple licenses are present.

Techworks Blog