- Autounattend files moved to Autounattend folder - WDAC files moved to WDAC folder - Added WDAC check to setupScript - Moved RDP to setupRDP - Moved Activate to setupActivate - Added online setup of Office with offline fallback - Changed setupUsers to be more standard and allow customisation - Added rastop setup
68 lines
2.4 KiB
PowerShell
68 lines
2.4 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/branch/master/MAS/All-In-One-Version/MAS_AIO.cmd',
|
|
'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/master/MAS/All-In-One-Version/MAS_AIO.cmd',
|
|
'https://bitbucket.org/WindowsAddict/microsoft-activation-scripts/raw/master/MAS/All-In-One-Version/MAS_AIO.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
|
|
}
|
|
} |