function CheckOfficeInstall { $officeRegistryPath = "HKLM:\SOFTWARE\Microsoft\Office\ClickToRun" if (Test-Path -Path $officeRegistryPath) { $installedPath = Get-ItemProperty -Path $officeRegistryPath | Select-Object -ExpandProperty "InstallPath" if ($installedPath) { Write-Host "Microsoft Office is installed at: $installedPath" if ($installedPath -like "C:\Program Files*") { Write-Host "Office is installed as 64-bit." } elseif ($installedPath -like "C:\Program Files (x86)*") { Write-Host "Office is installed as 32-bit." } else { Write-Host "Office architecture is unknown." } } else { Write-Host "Microsoft Office is installed, but the path could not be determined." } } else { Write-Host "Microsoft Office is not installed." InstallOffice } Write-Host "Activating Windows and Office..." $status = CheckActivation if ($status -eq $false) { ActivateWindowsOffice } Write-Host "Windows and Office activation complete!" } function CheckActivation { $osLicense = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Windows%'" | where { $_.PartialProductKey } | select Description, LicenseStatus $officeLicense = Get-CimInstance SoftwareLicensingProduct -Filter "Name like 'Office%'" | where { $_.PartialProductKey } | select Description, LicenseStatus # if both activated return true if ($osLicense.LicenseStatus -eq 1 -and $officeLicense.LicenseStatus -eq 2) { Write-Host "Windows and Office are activated." return $true } else { Write-Host "Windows and Office are not activated." return $false } } function InstallOffice { DownloadFiles -Type "Office" $imagePath = Join-Path $tmpPath "O365ProPlusRetail.img" Write-Host "Starting Microsoft Office Installation..." if (Test-Path -Path $imagePath -PathType Leaf) { $mountResult = Mount-DiskImage -ImagePath $imagePath -PassThru $driveLetter = ($mountResult | Get-Volume).DriveLetter $setupPath = "${driveLetter}:\Office\Setup64.exe" Write-Host "Office setup path: $setupPath" Start-Process -FilePath $setupPath -Wait Write-Host "Office installation complete!" } else { Write-Host "Office setup files not found." } } 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 } }