ActivationScripts.psm1
<#
.EXTERNALHELP ActivationScripts.psm1-Help.xml #> function Start-MicrosoftActivationScriptsAIO { [CmdletBinding(HelpUri = 'https://massgrave.dev/command_line_switches.html#Switches_List', SupportsShouldProcess = $true)] param ( [Parameter(Mandatory = $false, Position = 1, HelpMessage = 'Run in unattended mode.')] [ValidateSet('HWID', 'HWIDNoEditionChange', 'KMS38', 'KMS38RemoveProtection', 'KMS38NoEditionChange', 'WindowsKMS', 'OfficeKMS', 'WindowsOfficeKMS', 'RenewalTaskKMS', 'ActAndRenewalTaskKMS', 'UninstallKMS', 'KeepvNextKMS', 'DebugKMS', 'LoggerKMS', 'InsertKeyHWID', IgnoreCase = $true)] [ValidateNotNullOrEmpty()] [string]$switch, [Parameter(HelpMessage = 'No output.')] [switch]$Silent, [Parameter(DontShow = $true)] [switch]$Force ) if ($Force) { $PSCmdlet.ShouldProcess($psObject) } function Get-MAS2Temp { [CmdletBinding()] [OutputType([string])] param ( [switch]$GetPath ) Set-ExecutionPolicy -ExecutionPolicy Bypass -Scope Process -Force [Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 $DownloadURL = 'https://gitlab.com/massgrave/microsoft-activation-scripts/-/raw/master/MAS/All-In-One-Version/MAS_AIO.cmd' $DownloadURL2 = 'https://raw.githubusercontent.com/massgravel/Microsoft-Activation-Scripts/master/MAS/All-In-One-Version/MAS_AIO.cmd' $rand = Get-Random -Maximum 1000 $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" } try { $response = Invoke-WebRequest -Uri $DownloadURL -UseBasicParsing } catch { $response = Invoke-WebRequest -Uri $DownloadURL2 -UseBasicParsing } $prefix = "@REM $rand `r`n" $content = $prefix + $response Set-Content -Path $FilePath -Value $content if ($GetPath) { return $FilePath } } function Remove-MAStmp { [CmdletBinding(SupportsShouldProcess = $true)] param ( [switch]$Force ) if ($Force) { $PSCmdlet.ShouldProcess($psObject) } $FilePaths = @("$env:TEMP\MAS*.cmd", "$env:SystemRoot\Temp\MAS*.cmd") foreach ($FilePath in $FilePaths) { Get-Item $FilePath | Remove-Item -Force } } $ProgressPreference = 'SilentlyContinue' $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent()); if (!($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) { Write-Warning -Message "It is recommended to start MAS from elevated console."; Start-Sleep -Milliseconds 2300 } $switches = @{ 'HWID' = '/HWID' 'HWIDNoEditionChange' = '/HWID-NoEditionChange' 'KMS38' = '/KMS38' 'KMS38RemoveProtectio' = '/KMS38-RemoveProtection' 'KMS38NoEditionChange' = '/KMS38-NoEditionChange' 'WindowsKMS' = '/KMS-Windows' 'OfficeKMS' = '/KMS-Office' 'WindowsOfficeKMS' = '/KMS-WindowsOffice' 'RenewalTaskKMS' = '/KMS-RenewalTask' 'ActAndRenewalTaskKMS' = '/KMS-ActAndRenewalTask' 'UninstallKMS' = '/KMS-Uninstall' 'KeepvNextKMS' = '/KMS-KeepvNext' 'DebugKMS' = '/KMS-Debug' 'LoggerKMS' = '/KMS-Logger' 'InsertKeyHWID' = '/Insert-HWID-Key' } if ([bool]$switch) { $Arguments = $switches.Item($switch) } else { $Arguments = $null } $MASpath = (Resolve-Path (Get-MAS2temp -GetPath)).Path if (Test-Path -PathType Leaf -Path $MASpath -ErrorAction SilentlyContinue) { if ($Arguments) { if ($Silent) { $Arguments += " /S" }; Start-Process -FilePath $MASpath -ArgumentList $Arguments -NoNewWindow -Wait } else { if ($Silent) { Write-Warning -Message "Switch '-Silent' cannot be used without '-switch [Value]' parameter." } else { Start-Process -FilePath $MASpath -NoNewWindow -Wait; Clear-Host } } } else { Write-Error -Message "Error getting 'Microsoft Activation Scripts'" -Category ObjectNotFound } Remove-MAStmp -Force | Out-Null } |