Files

100 lines
4.7 KiB
PowerShell

<#function Get-ActivationStatus {
[CmdletBinding()]
param(
[Parameter(ValueFromPipeline = $true, ValueFromPipelineByPropertyName = $true)]
[string]$DNSHostName = $Env:COMPUTERNAME
)
process {
try {
$wpa = Get-WmiObject SoftwareLicensingProduct -ComputerName $DNSHostName `
-Filter "ApplicationID = '55c92734-d682-4d71-983e-d6ec3f16059f'" `
-Property LicenseStatus -ErrorAction Stop
} catch {
$status = New-Object ComponentModel.Win32Exception ($_.Exception.ErrorCode)
$wpa = $null
}
$out = New-Object psobject -Property @{
ComputerName = $DNSHostName;
Status = [string]::Empty;
}
if ($wpa) {
:outer foreach($item in $wpa) {
switch ($item.LicenseStatus) {
0 {$out.Status = "Unlicensed"}
1 {$out.Status = "Licensed"; break outer}
2 {$out.Status = "Out-Of-Box Grace Period"; break outer}
3 {$out.Status = "Out-Of-Tolerance Grace Period"; break outer}
4 {$out.Status = "Non-Genuine Grace Period"; break outer}
5 {$out.Status = "Notification"; break outer}
6 {$out.Status = "Extended Grace"; break outer}
default {$out.Status = "Unknown value"}
}
}
} else {$out.Status = $status.Message}
$out
}
}
Write-Verbose 'Checking if Windows is activated...'
sleep -Seconds 1
$Licensed = Get-ActivationStatus
IF (($Licensed.status -eq 'Licensed') -and (!$Force))
{
Write-host 'Windows is already activated.'
break
}
else
{
Write-host 'Windows will be deactivated.'
$OSversion = (Get-WmiObject -class Win32_OperatingSystem).Caption
switch -Regex ($OSversion) {
#windows 7
'Microsoft Windows 7 Professionnel' {$key = 'FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4';break}
'Microsoft Windows 7 Enterprise' {$key = '33PXH-7Y6KF-2VJC9-XBBR8-HVTHH';break}
#windows 8
'Microsoft Windows 8 Professional' {$key = 'NG4HW-VH26C-733KW-K6F98-J8CK4';break}
'Microsoft Windows 8 Enterprise' {$key = '32JNW-9KQ84-P47T8-D8GGY-CWCK7';break}
#Windows 8.1
'Microsoft Windows 8.1 Professionnel N' {$key = 'HMCNV-VVBFX-7HMBH-CTY9B-B4FXY';break}
'Microsoft Windows 8.1 Professionnel' {$key = 'GCRJD-8NW9H-F2CDX-CCM8D-9D6T9';break}
'Microsoft Windows 8.1 Enterprise N' {$key = 'TT4HM-HN7YT-62K67-RGRQJ-JFFXW';break}
'Microsoft Windows 8.1 Enterprise' {$key = 'MHF9N-XY6XB-WVXMC-BTDCT-MKKG7';break}
#Windows 10
'Microsoft Windows 10 Éducation' {$Key = 'NW6C2-QMPVW-D7KKK-3GKT6-VCFB2';break}
'Microsoft Windows 10 Professionnel' {$Key = 'W269N-WFGWX-YVC9B-4J6C9-T83GX';break}
'Microsoft Windows 10 Enterprise' {$Key = 'NPPR9-FWDCX-D2C8J-H872K-2YT43';break}
'Microsoft Windows 10 Enterprise 2015 LTSB' {$Key = 'WNMTR-4C88C-JK8YV-HQ7T2-76DF9';break}
#Windows Serveur 2008
'Microsoft Windows Server 2008 R2 Standard' {$Key = 'YC6KT-GKW9T-YTKYR-T4X34-R7VHC';break}
'Microsoft Windows Server 2008 R2 Enterprise' {$Key = '489J6-VHDMP-X63PK-3K798-CPX3Y';break}
'Microsoft Windows Server 2008 R2 Datacenter' {$Key = 'W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9';break}
'Microsoft Windows Server 2008 R2 Essentials' {$Key = 'KNC87-3J2TX-XB4WP-VCPJV-M4FWM';break}
#Windows Serveur 2012
'Microsoft Windows Server 2012 R2 Standard' {$key = 'D2N9P-3P6X9-2R39C-7RTCD-MDVJX';break}
'Microsoft Windows Server 2012 R2 Datacenter' {$key = 'W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9';break}
'Microsoft Windows Server 2008 R2 Enterprise' {$key = '489J6-VHDMP-X63PK-3K798-CPX3Y';break}
'Microsoft Windows Server 2012 R2 Essentials' {$key = 'KNC87-3J2TX-XB4WP-VCPJV-M4FWM';break}
#Windows Serveur 2016
'Microsoft Windows Server 2016 Standard' {$key = 'WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY';break}
'Microsoft Windows Server 2016 Datacenter' {$Key = 'CB7KF-BWN84-R7R2Y-793K2-8XDDG';break}
'Microsoft Windows Server 2016 Essentials' {$key = 'JCKRF-N37P4-C2D82-9YXRT-4M63B';break}
}#>
#Write-host "Operating system is $OSversion"
$kmshost = '10.0.14.20'
Write-Host "Le serveur KSM est defini sur $kmshost"
#Write-host "KMS client key is $Key"
sleep -Seconds 2
Write-host 'Forcing activation using slmgr script...'
cscript $env:windir\System32\slmgr.vbs /skms $kmshost 2>&1
#cscript $env:windir\System32\slmgr.vbs /ipk $key 2>&1
cscript $env:windir\System32\slmgr.vbs /ato 2>&1
break
#}