Reorganisation of the setup
- 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
This commit is contained in:
125
setupOffice.ps1
125
setupOffice.ps1
@@ -1,10 +1,46 @@
|
||||
function CheckOfficeInstall {
|
||||
function InstallOffice {
|
||||
param (
|
||||
[string] $mode
|
||||
)
|
||||
if ($mode -eq "offline") {
|
||||
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."
|
||||
}
|
||||
}
|
||||
else if ($mode -eq "online") {
|
||||
DownloadFiles -Type "Office-online"
|
||||
$setupPath = Join-Path $tmpPath "OfficeSetup.exe"
|
||||
Write-Host "Starting Microsoft Office Installation..."
|
||||
if (Test-Path -Path $setupPath -PathType Leaf) {
|
||||
Start-Process -FilePath $setupPath -Wait
|
||||
Write-Host "Office installation complete!"
|
||||
} else {
|
||||
Write-Host "Office setup files not found."
|
||||
}
|
||||
}
|
||||
else {
|
||||
Write-Host "Invalid mode. Please choose 'online' or 'offline'."
|
||||
}
|
||||
}
|
||||
|
||||
function CheckIfOfficeIsInstalled {
|
||||
$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)*") {
|
||||
@@ -15,88 +51,23 @@ function CheckOfficeInstall {
|
||||
} else {
|
||||
Write-Host "Microsoft Office is installed, but the path could not be determined."
|
||||
}
|
||||
} else {
|
||||
Write-Host "Microsoft Office is not installed."
|
||||
InstallOffice
|
||||
}
|
||||
$status = CheckActivation
|
||||
if ($status -eq $false) {
|
||||
Write-Host "Activating Windows and Office..."
|
||||
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!"
|
||||
function SetupOffice {
|
||||
Write-Host "Setting up Microsoft Office..."
|
||||
if (CheckIfOfficeIsInstalled) {
|
||||
Write-Host "Office is already installed! Skipping..."
|
||||
} 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"
|
||||
Write-Host "Office is not installed."
|
||||
InstallOffice -mode "online"
|
||||
Start-Sleep -s 20
|
||||
if (-not (CheckIfOfficeIsInstalled)) {
|
||||
Write-Host "Office installation failed. Trying again using offline setup..."
|
||||
InstallOffice -mode "offline"
|
||||
}
|
||||
}
|
||||
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