A PowerShell script for installing and activating Windows using a valid product license key. This tool provides a streamlined command-line interface for Windows activation with proper error handling and status reporting.
This script automates the Windows activation process by installing a product key and triggering the activation sequence through Windows Management Instrumentation (WMI). It includes validation checks, administrator privilege verification, and detailed status reporting to ensure a smooth activation experience.
- Automated License Installation: Installs Windows product keys programmatically
- Activation Trigger: Initiates the Windows activation process
- Status Reporting: Provides detailed activation status with clear visual feedback
- Input Validation: Validates product key format before processing
- Error Handling: Comprehensive error catching and user-friendly error messages
- Administrator Check: Verifies script is run with required privileges
- Color-Coded Output: Visual feedback using colored console messages
- Operating System: Windows (any edition that supports activation)
- PowerShell: Version 5.1 or higher
- Privileges: Administrator rights (required)
- Valid Product Key: A legitimate Windows license key in the format
XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
-
Download the
windows-activation.ps1script to your local machine -
Open the script in a text editor
-
Locate the configuration section at the top of the file:
# CONFIGURATION - Enter your license key here
$LicenseKey = "XXXXX-XXXXX-XXXXX-XXXXX-XXXXX"- Replace the placeholder with your actual Windows product key:
$LicenseKey = "ABCDE-12345-FGHIJ-67890-KLMNO"- Save the file
-
Open PowerShell as Administrator:
- Right-click the Start menu
- Select "Windows PowerShell (Admin)" or "Terminal (Admin)"
-
Navigate to the script directory:
cd C:\path\to\script- Execute the script:
.\windows-activation.ps1Successful activation:
========================================
Windows Activation Script
========================================
Installing product key...
Product key installed successfully.
Activating Windows...
Activation completed.
========================================
Activation Status
========================================
Status: Licensed (Activated)
Windows has been activated successfully!
windows-activation-script/
├── windows-activation.ps1 # Main PowerShell activation script
└── README.md
The script is organized into the following sections:
- Configuration Section: Where the license key is defined
- Functions:
Test-AdminPrivileges: Checks if the script is running with administrator rightsInstall-ProductKey: Installs the Windows product key using WMIInvoke-WindowsActivation: Triggers the Windows activation processGet-ActivationStatus: Retrieves and formats the current activation status
- Main Execution Block: Orchestrates the activation workflow
The product key must follow this exact format:
- 5 groups of 5 characters
- Separated by hyphens
- Alphanumeric characters (A-Z, 0-9)
- Example:
ABCDE-12345-FGHIJ-67890-KLMNO
The script reports the following status codes:
| Code | Status | Description |
|---|---|---|
| 0 | Unlicensed | Windows is not activated |
| 1 | Licensed (Activated) | Windows is successfully activated |
| 2 | Out-of-Box Grace Period | Initial grace period active |
| 3 | Out-of-Tolerance Grace Period | Hardware changes detected |
| 4 | Non-Genuine Grace Period | Validation issues |
| 5 | Notification | Activation notification state |
| 6 | Extended Grace Period | Extended grace period active |
-
Valid License Required: This script only works with legitimate Windows product keys. It does not bypass activation or provide unauthorized licenses.
-
Internet Connection: Windows activation typically requires an internet connection to communicate with Microsoft's activation servers. Offline activation may require additional steps not covered by this script.
-
One-Time Configuration: The license key is hardcoded in the script. For security reasons, avoid sharing the configured script file.
-
Regional Restrictions: Some product keys are region-specific and may not work in all geographic locations.
-
Edition Compatibility: Ensure your product key matches your Windows edition (Home, Pro, Enterprise, etc.).
- The script does not support batch activation of multiple machines
- No built-in rollback mechanism if activation fails
- Requires manual editing of the script file to change the product key
Error: "This script requires Administrator privileges"
- Solution: Run PowerShell as Administrator
Error: "The key format is not valid"
- Solution: Verify your product key follows the format
XXXXX-XXXXX-XXXXX-XXXXX-XXXXX
Error: "Error installing key"
- Solution: Ensure the product key is valid and matches your Windows edition
Status shows "Unlicensed" after activation
- Solution: Check your internet connection and wait a few minutes for activation to process