Remove Office 365 license from a Computer with PowerShell

One of my users got a notice in Office 2016 that he needed to reactivate his Office 365 subscription. After clicking reactivated a warning came up that “there was a problem with your Office 365 subscription, and we need your help to fix it“. The problem was that the registered license belonged to a user that was no longer working at our company and that license was revoked. So how can we remove the Office 365 license from this computer?

Finding out the real problem

First I wanted to know why the license was not working anymore. In Office 365 the licenses are assigned to a user. When you remove the user and revoke the license then within 90-days the installed Office 2016 will no longer work. During this grace period, you can buy / re-assign the license to the new user.

Now to check if the computer in question is licensed by this user you can log in to Office 365 and goto the My Account page: Here you see an overview of the devices on which the license is used.

Another way to check who’s license is used for the Office Installation is to open Word or Outlook and go the File > Office Account

Office 365 Remove License

Here you see on the right side under the Office 365 Logo Belongs To.

Remove the Office 365 license

Removing the old Office 365 license from the computer is really simple. You can use PowerShell or CMD for the steps below:

1. Open PowerShell or CMD

First, we need to open PowerShell or CMD in Administrator mode. Click on Start and type PowerShell and right click on the icon. Select Run as Administrator

2. List current licenses

If you are using PowerShell run the following command to list activated licenses:

cscript "$Env:Programfiles\Microsoft Office\Office16\OSPP.VBS" /dstatus

If you are using CMD then run the following cmd:

cscript "%Programfiles%\Microsoft Office\Office16\OSPP.VBS" /dstatus

3. Finding the expiring license

The output of the command looks like below. There could be more than one key listed, so look for a license with a REMAINING GRACE or Grace Periode Expired line just above the last 5 characters of the product key.

Take a note of the 5 last characters of the product key that we need to remove.

Remove Office 2016 license with PowerShell

4. Removing the product key

Run the command below to remove the license that is or is about to expire. Replace <key> with the 5 characters of the product key:

cscript "$Env:Programfiles\Microsoft Office\Office16\OSPP.VBS" /unpkey:<key>

The command if you are using CMD:

cscript "%Programfiles%\Microsoft Office\Office16\OSPP.VBS" /unpkey:<key>

Activating the license of the new user

If you need to activate a new license, you can just restart an Office program. The user just needs to login to active it again.

You might also like:

Get more stuff like this

IT, Office365, Smart Home, PowerShell and Blogging Tips

I hate spam to, so you can unsubscribe at any time.

8 thoughts on “Remove Office 365 license from a Computer with PowerShell”

  1. I find this solution unacceptable as an IT administrator in an enterprise with an O365 Enterprise license. No offense to you, Rudy, but is this seriously the ONLY way for administrators to deactivate terminated employees’ licenses to O365 on a workstation–individually, workstation by workstation?

    As an O365 global admin, I *should* be able to deactivate any install for any user from the Admin center. Or, at the very least, with a PowerShell command. Having my IT department go around and manually deactivate licenses on workstations is just not possible.

    Again, this is not a complaint of your solution but just about the the ridiculousness of Microsoft thinking this is how it should be done in an enterprise environment.

  2. I get this when I put in both commands:

    Error: Can not find script file “C:\Program Files\Microsoft Office\Office16\OSPP.VBS”. C:\Windows\system32>

    • Which version of Office are you using? Check your program files or program files x86 folder for Microsoft Office\Office16\OSPP.VBS and change the path in the script to the right location.

  3. Thank you, thank you, thank you!!! I wasted almost and entire day going round and round trying to remove 365. I had installed 2019 as it is part of my MPN program and was trying to switch. Nothing worked until I tried this.

  4. Worked perfectly removing duplicate key registration. Found and removed office 365 activation annoying popup

  5. Hey Rudy, thanks so much for this. Home 365 user in my case, but I’ve had regular expiry/grace problems due to an expired 365 ProPlus sub which I couldn’t remove. MS couldn’t/wouldn’t help, your simple steps have fixed it.

Leave a Comment