salt.modules.win_license#

Manage licensing for products using Windows Software Licensing Service via PowerShell CIM.

Supports management of Windows OS, Microsoft Office, and other Microsoft products that use the Software Licensing Service (KMS and MAK activation).

Requires Windows 7 / Windows Server 2008 R2 or later. Replaces the previous slmgr.vbs-based implementation.

Changed in version 3008.2: Reimplemented using PowerShell CIM instead of slmgr.vbs (VBScript). Now supports managing any product using the Software Licensing Service, not just Windows OS.

salt '*' license.install XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
salt.modules.win_license.activate(product_key=None)#

Activate a product using the Software Licensing Service.

Parameters:

product_key (str) -- Optional product key to activate. If not provided, activates the Windows OS product key (if installed).

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.activate
salt '*' license.activate XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.clear_kms_host(product_key=None)#

Clear the KMS host for a product key.

If product_key is not provided, clears the global KMS host.

Parameters:

product_key (str) -- Optional product key. If not provided, clears global KMS host.

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.clear_kms_host
salt '*' license.clear_kms_host XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.clear_kms_port(product_key=None)#

Clear the KMS port for a product key.

If product_key is not provided, clears the global KMS port.

Parameters:

product_key (str) -- Optional product key. If not provided, clears global KMS port.

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.clear_kms_port
salt '*' license.clear_kms_port XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.get_kms_host(product_key=None)#

Get the KMS host for a product key.

If product_key is not provided, returns the global KMS host.

Parameters:

product_key (str) -- Optional product key. If not provided, returns global KMS host.

Returns:

The KMS host name or IP address, or None if not set

Return type:

str

CLI Example:

salt '*' license.get_kms_host
salt '*' license.get_kms_host XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.get_kms_port(product_key=None)#

Get the KMS port for a product key.

If product_key is not provided, returns the global KMS port.

Parameters:

product_key (str) -- Optional product key. If not provided, returns global KMS port.

Returns:

The KMS port number, or None if not set

Return type:

int

CLI Example:

salt '*' license.get_kms_port
salt '*' license.get_kms_port XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.info(product_key=None)#

Return information about a product license.

Parameters:

product_key (str) -- Optional product key to get info for. If not provided, returns information about the Windows OS product key (if installed).

Returns:

License information containing:
  • name: Product name

  • description: Product description

  • partial_key: Last 5 digits of the product key

  • licensed: Boolean, True if status is Licensed (status == 1)

  • status: License status code (0-6)

  • status_name: Human-readable status name

Status codes and names: - 0: Unlicensed - 1: Licensed - 2: OOBGrace - 3: OOTGrace - 4: NonGenuineGrace - 5: Notification - 6: ExtendedGrace

Return type:

dict

Returns None if product not found.

CLI Example:

salt '*' license.info
salt '*' license.info XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.install(product_key)#

Install the given product key

Parameters:

product_key (str) -- The product key to install.

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.install XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
salt.modules.win_license.installed(product_key)#

Check to see if the product key is already installed.

Note: This is not 100% accurate as we can only see the last

5 digits of the license.

Parameters:

product_key (str) -- The product key to check.

Returns:

True if the last 5 digits match the current product key,

otherwise False.

Return type:

bool

CLI Example:

salt '*' license.installed XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
salt.modules.win_license.license_status(product_key=None)#

Get the license status code for a product key.

Parameters:

product_key (str) -- Optional product key to check. If not provided, checks the Windows OS product key (if installed).

Returns:

License status code:
  • 0: Unlicensed

  • 1: Licensed (valid and activated)

  • 2: OOBGrace (out of box grace period)

  • 3: OOTGrace (out of tolerance grace period)

  • 4: NonGenuineGrace (non-genuine grace period)

  • 5: Notification (notification period)

  • 6: ExtendedGrace (extended grace period)

Return type:

int

CLI Example:

salt '*' license.license_status
salt '*' license.license_status XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.licensed(product_key=None)#

Check if a product is properly licensed and activated.

Parameters:

product_key (str) -- Optional product key to check. If not provided, checks the Windows OS product key (if installed).

Returns:

True if the product has a license status of 1 (Licensed and activated),

False otherwise (including grace periods and unlicensed states)

Return type:

bool

CLI Example:

salt '*' license.licensed
salt '*' license.licensed XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.set_kms_host(host, product_key=None)#

Set the KMS host for a product key.

If product_key is not provided, sets the global KMS host.

Parameters:
  • host (str) -- The KMS host name or IP address.

  • product_key (str) -- Optional product key. If not provided, sets global KMS host.

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.set_kms_host kms.example.com
salt '*' license.set_kms_host kms.example.com XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.set_kms_port(port, product_key=None)#

Set the KMS port for a product key.

If product_key is not provided, sets the global KMS port.

Parameters:
  • port (int) -- The KMS port number.

  • product_key (str) -- Optional product key. If not provided, sets global KMS port.

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.set_kms_port 1688
salt '*' license.set_kms_port 1688 XXXXX-XXXXX-XXXXX-XXXXX-ABCDE
salt.modules.win_license.uninstall(product_key=None)#

Uninstall a product key.

Parameters:

product_key (str) -- Optional product key to uninstall. If not provided, uninstalls the Windows OS product key (if installed). Specify a product key to uninstall other products (e.g., Microsoft Office).

Returns:

Success message

Return type:

str

Raises:

CommandExecutionError -- on failure

CLI Example:

salt '*' license.uninstall
salt '*' license.uninstall XXXXX-XXXXX-XXXXX-XXXXX-ABCDE