1. Remove Office 365 license for Subscription based installs (not Shared Computer Licensing scenarios):
To remove the Office 365 license, you must run two cscript command lines. The command lines are:
A. Run C:\program files <x86>\Microsoft office\office15>cscript ospp.vbs /dstatus
The above command line will generate a report of the currently installed/activated license. (See Below)
NOTE: You might see multiple licenses in the /dstatus report.
B. Make note of value for “Last 5 characters of installed product key”
C. Run C:\program files <x86>\Microsoft office\office15>cscript ospp.vbs /unpkey:“Last 5 of installed product key” For example: C:\program files <x86>\Microsoft office\office15>cscript ospp.vbs /unpkey:WB222 (See Below) Repeat the step above if necessary until all keys are removed.
After running the /unpkey: command line you will see a “Product Key uninstall successful” message. You can now close the Command Prompt and move onto Step 2.
2. Remove cached identities in HKCU registry:
A. In the Registry Editor navigate to HKCU\Software\Microsoft\Office\15.0 or 16.0\Common\Identity\Identities and remove all of the identities under \Identities.
NOTE: If using Shared Computer Licensing remove the above Identities from HKEYUsers\SID.
3. Remove the stored Credentials in the Credential Manager:
A. Open Control Panel > Credential Manager. Remove all Windows credentials listed for Office15 or Office16.
B. To remove the Credential Click on the Drop down arrow and choose Remove from Vault.(See Below)
4. Ran following script in PowerShell (Run as Administrator):
#Check that the script runs with privileged rights
if (-not([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")) {
Write-Warning "You need to have Administrator rights to run this script!`nPlease re-run this script as an Administrator in an elevated powershell prompt!"
break
}
#Find OSPP.vbs path and run the command with the dstatus option (Last 1...)
$OSPP = Resolve-Path -Path "C:\Program Files*\Microsoft Office\Office16\ospp.vbs" | Select-Object -ExpandProperty Path -Last 1
Write-Output -InputObject "OSPP Location is: $OSPP"
$Command = "cscript.exe '$OSPP' /dstatus"
$DStatus = Invoke-Expression -Command $Command
#Get product keys from OSPP.vbs output.
$ProductKeys = $DStatus | Select-String -SimpleMatch "Last 5" | ForEach-Object -Process { $_.tostring().split(" ")[-1]}
if ($ProductKeys) {
Write-Output -InputObject "Found $(($ProductKeys | Measure-Object).Count) productkeys, proceeding with deactivation..."
#Run OSPP.vbs per key with /unpkey option.
foreach ($ProductKey in $ProductKeys) {
Write-Output -InputObject "Processing productkey $ProductKey"
$Command = "cscript.exe '$OSPP' /unpkey:$ProductKey"
Invoke-Expression -Command $Command
}
} else {
Write-Output -InputObject "Found no keys to remove... "
}