Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Windows 11 product key
- $Key = "PUT-KEY-HERE"
- # Function to check activation status
- function Check-ActivationStatus {
- $activationInfo = (Get-WmiObject -Class SoftwareLicensingProduct | Where-Object { $_.PartialProductKey -ne $null -and $_.LicenseFamily -like "*Windows*" })
- return $activationInfo | Select-Object -ExpandProperty LicenseStatus
- }
- # Check activation status
- $activationStatus = Check-ActivationStatus
- if ($activationStatus -eq 1) {
- Write-Host "Windows is activated. No action needed."
- } else {
- Write-Host "Windows is not activated. Attempting to install and activate the key..."
- # Installing Key
- try {
- slmgr.vbs /ipk $Key
- Write-Host "Product key installed successfully."
- # Activating Windows
- slmgr.vbs /ato
- Write-Host "Activation attempted."
- # Check activation status after activating
- $activationStatus = Check-ActivationStatus
- if ($activationStatus -eq 1) {
- Write-Host "Windows is now activated."
- } else {
- Write-Host "Activation failed."
- }
- } catch {
- Write-Host "An error occurred: $_"
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement