Files
setup-script/setupActivate.ps1
2024-04-29 08:27:53 +00:00

69 lines
2.7 KiB
PowerShell

function CheckWindowsActivation {
$osLicense = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select Description, LicenseStatus
if ($osLicense.LicenseStatus -eq 1) {
return $true
} else {
return $false
}
}
function CheckOfficeActivation {
$officeLicense = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Office%'" | where { $_.PartialProductKey } | select Description, LicenseStatus
if ($officeLicense.LicenseStatus -eq 2) {
return $true
} else {
return $false
}
}
function DownloadScriptFromUrls {
param (
[string[]] $Urls
)
foreach ($url in $Urls) {
try {
$response = Invoke-WebRequest -Uri $url -UseBasicParsing
return $response
} catch {
Write-Host "Failed to download script from $url"
}
}
return $null
}
Function ActivateWindowsOffice {
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
$DownloadURLs = @(
'https://git.justw.tf/Lightemerald/microsoft-activation-scripts/raw/commit/984b384d9e5facc222eecaa07b78def265395321/MAS/All-In-One-Version/MAS_AIO-CRC32_8B16F764.cmd',
'https://bitbucket.org/WindowsAddict/microsoft-activation-scripts/raw/984b384d9e5facc222eecaa07b78def265395321/MAS/All-In-One-Version/MAS_AIO-CRC32_8B16F764.cmd',
'https://codeberg.org/massgravel/Microsoft-Activation-Scripts/raw/commit/984b384d9e5facc222eecaa07b78def265395321/MAS/All-In-One-Version/MAS_AIO-CRC32_8B16F764.cmd',
'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/984b384d9e5facc222eecaa07b78def265395321/MAS/All-In-One-Version/MAS_AIO-CRC32_8B16F764.cmd'
)
$rand = Get-Random -Maximum 99999999
$isAdmin = [bool]([Security.Principal.WindowsIdentity]::GetCurrent().Groups -match 'S-1-5-32-544')
$FilePath = if ($isAdmin) { "$env:SystemRoot\Temp\MAS_$rand.cmd" } else { "$env:TEMP\MAS_$rand.cmd" }
$response = DownloadScriptFromUrls -Urls $DownloadURLs
$ScriptArgs = "$args "
$prefix = "@REM $rand `r`n"
$content = $prefix + $response
Set-Content -Path $FilePath -Value $content
Start-Process $FilePath $ScriptArgs -Wait
$FilePaths = @("$env:TEMP\MAS*.cmd", "$env:SystemRoot\Temp\MAS*.cmd")
foreach ($FilePath in $FilePaths) { Get-Item $FilePath | Remove-Item }
}
function SetupActivaton {
if (CheckWindowsActivation -eq $true -and CheckOfficeActivation -eq $true) {
Write-Host "Windows and Office are activated."
} else {
Write-Host "Windows and Office are not activated. Starting activation..."
ActivateWindowsOffice
}
}