First version of unified script
This commit is contained in:
80
setupOffice.ps1
Normal file
80
setupOffice.ps1
Normal file
@@ -0,0 +1,80 @@
|
||||
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
|
||||
}
|
||||
ActivateWindowsOffice
|
||||
}
|
||||
|
||||
function InstallOffice {
|
||||
$imagePath = Join-Path $tmpPath "O365ProPlusRetail.img"
|
||||
$setupPath = Join-Path $driveLetter '\Office\Setup64.exe'
|
||||
|
||||
Write-Host "Starting Microsoft Office Installation..."
|
||||
|
||||
if (Test-Path -Path $imagePath -PathType Leaf -and Test-Path -Path $setupPath -PathType Leaf) {
|
||||
$mountResult = Mount-DiskImage -ImagePath $imagePath -PassThru
|
||||
$driveLetter = ($mountResult | Get-Volume).DriveLetter
|
||||
Start-Process -FilePath $setupPath -Wait
|
||||
} 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 }
|
||||
}
|
||||
Reference in New Issue
Block a user