Remove-O365License
Description
Removes all Office 365 / Microsoft 365 license activations from the local device using ospp.vbs and SoftwareLicensingProduct WMI. Cleans up cached license files and related registry keys.
Supports scheduling the removal for a future date via the -Days or -Minutes parameter, which creates a Windows Scheduled Task to run the removal automatically.
Requirements
- PowerShell 5+
- Run as Administrator
- Access to PowerShell Gallery to install or update the
Strappermodule
Process
- Sets TLS policy for secure module and web requests.
- Ensures the
Strappermodule is installed and up to date, then initializes the Strapper environment. - Locates
ospp.vbsfrom the local Office installation. - Queries
SoftwareLicensingProductfor all Office license activations (ApplicationID matching0ff1ce). - Prompts the user for confirmation unless
-Forceis specified. - If
-Daysor-Minutesis specified, creates a Windows Scheduled Task to run the removal after the specified duration and exits. - Removes each product key via
ospp.vbs /unpkey(preferred) or falls back to theUninstallProductKeyWMI method. - Clears cached KMS host information via
ospp.vbs /remhst. - Removes cached license token files from
%LOCALAPPDATA%and%ProgramData%. - Removes Office identity and licensing registry keys under
HKCU:\Software\Microsoft\Office\16.0.
Usage
.\Remove-O365License.ps1
Removes all Office 365 licenses without prompting.
.\Remove-O365License.ps1 -Days 30
Schedules the license removal to run automatically in 30 days via a Scheduled Task.
.\Remove-O365License.ps1 -Minutes 5
Schedules the license removal to run automatically in 5 minutes via a Scheduled Task.
Parameters
| Parameter | Alias | Required | Default | Type | Description |
| --------- | ----- | -------- | ------- | ------ | -------------------------------------------------------------------------------- | |
| Days | | False | | Int | Number of days to wait before removing the license via a Scheduled Task (1-365). |
| Minutes | | False | | Int | Number of minutes to wait before removing the license via a Scheduled Task. |
Output
.\Remove-O365License-log.txt
Changelog
2026-06-17
- Initial version of the document