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: https://portal.office.com/account/. 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:

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

  1. THANK YOU THANK YOU THANK YOU

    DUDE…. THANK YOU SO MUCH

    this took so damn long. i was stuck before this article. you are doing great work.

  2. Thank you very much, but after removing the MSOffice licence from the other pc, does the ”get genuine office” notification stop??

  3. really nice guide, thanks… just a heads up, if you get an error saying it could not find the script file, try the x86 folder, so just add (x86) at the end of programfiles

    ie:
    cscript “%Programfiles(x86)%\Microsoft Office\Office16\OSPP.VBS” /dstatus
    and
    cscript “%Programfiles(x86)%\Microsoft Office\Office16\OSPP.VBS” /unpkey:

  4. Hi Rudy,

    Just to make sure I understand correctly , Removing the product key can be used to sign-out from a specific device. Without de-activating the user license, correct??

  5. Thank you – thank you – thank you!!!
    Your advice saved me from having to reformat my laptop.
    I had an Office 365 installation on my laptop, license provided by my former employer. Unfortunately, it seems that they forgot to remove my laptop from their account and I had no way to ask them to do it for me. That didn’t bother me until the license expired recently,
    I tried to install Office 2019 but the product indicated that it was unlicensed, showing two separate sections under “Account” tab; one for an activated Office 2019 and one unlicensed Office 365. I tried removing and reinstalling Office multiple times, even used the tools provided by Microsoft to no avail. After extensive googling, your advice did the trick!
    I might kindly add that the key removal command required admin rights on my laptop, whereas both commands can also run on plain command prompt (powershell is not necessary).
    Regards

  6. Hi Rudy,

    Thanks for the above instructions. I have a related problem, but the above does not appear to solve my issue. I have my original personal Office 365 on my computer, which license key is noted when I run the above. However, for some reason my companies issued subscription to Office 365 Pro Plus is now also on my personal laptop, but that license does not show up when I run the above script. Even when I try to access details of my personal Office Account, it forwards me to the Pro Plus corporate account. Even when I use the Device option to sign out of my personal laptop, it does not remove the subscription key.

    Any suggestions on I can remove the Pro Plus subscription key?
    Frank

    • In my understanding, you will only see the license that is used for activating Office. I have Office 365 which is licensed by the company I work for and Office 365 personally, only the first one is displayed.

      But what do you see when you look under file > Office account in one of the Office apps?

  7. 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.

  8. 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.

  9. 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.

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

  11. 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

0 Shares
Tweet
Pin
Share
Share