remove version pinning except for latest supported version for Windows 10
removed checksums, rely only on direct MS download completeness
This commit is contained in:
@@ -52,6 +52,15 @@ function Get-OfficeDeploymentDefinitions {
|
||||
MinimumServerBuild = 20348
|
||||
MinimumServerRevision = 2402
|
||||
Windows11Build = 22000
|
||||
# Windows 10 stays on this feature release; resolve its latest published build
|
||||
# per channel at run time rather than maintaining a fixed patch/build number.
|
||||
Windows10OfficeRelease = '2608'
|
||||
OfficeReleaseHistory = 'https://learn.microsoft.com/en-us/officeupdates/update-history-microsoft365-apps-by-date'
|
||||
OfficeReleaseHistoryChannels = @{
|
||||
Current = 'current-channel'
|
||||
MonthlyEnterprise = 'monthly-enterprise-channel'
|
||||
SemiAnnual = 'semi-annual-enterprise-channel'
|
||||
}
|
||||
TeamsUnsupportedWindows10Editions = @('EnterpriseS', 'EnterpriseSN', 'IoTEnterpriseS')
|
||||
# Teams.exe is classic, msteams.exe is the older personal/Windows Chat client,
|
||||
# and ms-teams.exe is the current client. Check all three before removal.
|
||||
@@ -103,6 +112,8 @@ function Get-OfficeDeploymentOptions {
|
||||
$company = $company.Trim()
|
||||
if ($company -eq 'None') { $company = '' }
|
||||
$options = @{ OfficeSubscription = $subscription; ProductId = $plans[$subscription]; Company = $company; ValidateBeforeChanges = $validateOnly; DeferReboot = $deferReboot }
|
||||
# Internal values, populated from the host and Microsoft's release history, not RMM input.
|
||||
$options.OfficeFeatureRelease = ''; $options.TargetOfficeVersion = ''
|
||||
# Derive this from the validated product mapping, including standalone Apps plans and legacy aliases.
|
||||
$options.InstallTeams = $options.ProductId -in $definitions.TeamsProducts
|
||||
foreach ($name in $choices.Keys) {
|
||||
@@ -131,6 +142,33 @@ function Assert-OfficeDeploymentHost {
|
||||
$os = Get-CimInstance Win32_OperatingSystem -ErrorAction Stop
|
||||
$windows = Get-ItemProperty -LiteralPath 'HKLM:\SOFTWARE\Microsoft\Windows NT\CurrentVersion' -ErrorAction Stop
|
||||
Assert-OfficeCompanionPlatform -Build ([int]$os.BuildNumber) -ProductType ([int]$os.ProductType) -Revision ([int]$windows.UBR) -EditionId $windows.EditionID -InstallTeams $Options.InstallTeams
|
||||
$Options.OfficeFeatureRelease = Get-OfficeFeatureRelease -Build ([int]$os.BuildNumber) -ProductType ([int]$os.ProductType)
|
||||
$null = Write-Output "Deployment host: $($os.Caption), build $($os.BuildNumber).$($windows.UBR)."
|
||||
}
|
||||
|
||||
function Get-OfficeFeatureRelease {
|
||||
param([int]$Build, [int]$ProductType)
|
||||
$definitions = Get-OfficeDeploymentDefinitions
|
||||
if ($ProductType -eq 1 -and $Build -ge $definitions.MinimumWindowsBuild -and $Build -lt $definitions.Windows11Build) { return $definitions.Windows10OfficeRelease }
|
||||
return ''
|
||||
}
|
||||
|
||||
function Get-OfficeBuildFromHistory {
|
||||
param([string]$PageContent, [string]$UpdateChannel, [string]$FeatureRelease)
|
||||
$definitions = Get-OfficeDeploymentDefinitions
|
||||
$article = $definitions.OfficeReleaseHistoryChannels[$UpdateChannel]
|
||||
if (!$article -or $FeatureRelease -notmatch '^\d{4}$') { throw 'Invalid Office release-history selection.' }
|
||||
$linkPattern = '(^|/)' + [regex]::Escape($article) + '#version-' + $FeatureRelease + '(?:-|$)'
|
||||
$labelPattern = '^\s*Version\s+' + $FeatureRelease + '\s+\(Build\s+(?<build>\d+\.\d+)\)\s*$'
|
||||
$content = [Net.WebUtility]::HtmlDecode($PageContent)
|
||||
$builds = @(foreach ($link in [regex]::Matches($content, '<a\b[^>]*\bhref\s*=\s*["''](?<href>[^"'']+)["''][^>]*>(?<label>.*?)</a>', 'IgnoreCase,Singleline')) {
|
||||
if ($link.Groups['href'].Value -notmatch $linkPattern) { continue }
|
||||
$label = $link.Groups['label'].Value -replace '<[^>]+>', ''
|
||||
if ($label -match $labelPattern) { [version]('16.0.' + $Matches['build']) }
|
||||
})
|
||||
$latest = $builds | Sort-Object -Descending -Unique | Select-Object -First 1
|
||||
if (!$latest) { throw "Microsoft's release history did not identify an Office $FeatureRelease build for $UpdateChannel. Existing Office has not been removed." }
|
||||
$latest.ToString()
|
||||
}
|
||||
|
||||
function Assert-OfficeCompanionPlatform {
|
||||
@@ -280,14 +318,13 @@ function Get-OfficeMediaCacheKey {
|
||||
$definitions = Get-OfficeDeploymentDefinitions
|
||||
# Company, activation, app shutdown, and reboot choices affect XML, not the payload.
|
||||
$contract = [ordered]@{
|
||||
Schema=1; Product=$Options.ProductId; Architecture=$Options.OfficeArchitecture
|
||||
Schema=2; Product=$Options.ProductId; Architecture=$Options.OfficeArchitecture
|
||||
Channel=$Options.UpdateChannel; Language=$definitions.Language
|
||||
TargetVersion=$Options.TargetOfficeVersion
|
||||
OdtPage=$definitions.OdtPage; ExcludedApps=$definitions.OdtExcludedApps
|
||||
Downloads=@(Get-OfficeCompanionDownloads -InstallTeams $Options.InstallTeams | ForEach-Object { "$($_.Name)|$($_.File)|$($_.Uri)" })
|
||||
}
|
||||
$sha = [Security.Cryptography.SHA256]::Create()
|
||||
try { ([BitConverter]::ToString($sha.ComputeHash([Text.Encoding]::UTF8.GetBytes(($contract | ConvertTo-Json -Depth 5 -Compress))))).Replace('-', '') }
|
||||
finally { $sha.Dispose() }
|
||||
$contract | ConvertTo-Json -Depth 5 -Compress
|
||||
}
|
||||
|
||||
function Save-OfficeMediaCache {
|
||||
@@ -296,10 +333,10 @@ function Save-OfficeMediaCache {
|
||||
$files = @()
|
||||
foreach ($name in @('ODT', 'odt.exe') + @(Get-OfficeCompanionDownloads -InstallTeams $Options.InstallTeams | ForEach-Object { $_.File })) {
|
||||
foreach ($file in @(Get-OfficeManagedFiles $root (Join-Path $Workspace $name))) {
|
||||
$files += [pscustomobject]@{ Path=$file.FullName.Substring($Workspace.TrimEnd('\').Length + 1); Length=$file.Length; Hash=(Get-FileHash -LiteralPath $file.FullName -Algorithm SHA256 -ErrorAction Stop).Hash }
|
||||
$files += [pscustomobject]@{ Path=$file.FullName.Substring($Workspace.TrimEnd('\').Length + 1); Length=$file.Length }
|
||||
}
|
||||
}
|
||||
[ordered]@{ Schema=1; Key=(Get-OfficeMediaCacheKey $Options); CreatedUtc=$CreatedUtc; Version=$Media.Version; Files=$files } |
|
||||
[ordered]@{ Schema=2; Key=(Get-OfficeMediaCacheKey $Options); CreatedUtc=$CreatedUtc; Version=$Media.Version; Files=$files } |
|
||||
ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $Workspace 'media-cache.json') -Encoding UTF8 -ErrorAction Stop
|
||||
}
|
||||
|
||||
@@ -317,17 +354,18 @@ function Restore-OfficeMediaCache {
|
||||
Assert-OfficeManagedPath $root $manifestPath
|
||||
$manifest = Get-Content -LiteralPath $manifestPath -Raw -ErrorAction Stop | ConvertFrom-Json -ErrorAction Stop
|
||||
$created = [DateTime]::Parse($manifest.CreatedUtc).ToUniversalTime()
|
||||
if ($manifest.Schema -ne 1 -or $manifest.Key -ne $key -or $created -gt [DateTime]::UtcNow -or $created -lt [DateTime]::UtcNow.AddDays(-$definitions.MediaCacheDays)) { continue }
|
||||
if ($manifest.Schema -ne 2 -or $manifest.Key -ne $key -or $created -gt [DateTime]::UtcNow -or $created -lt [DateTime]::UtcNow.AddDays(-$definitions.MediaCacheDays)) { continue }
|
||||
if ($manifest.Version -notmatch $definitions.OfficeBuildPattern -or !$manifest.Files.Count) { throw 'Invalid cache manifest.' }
|
||||
if ($Options.TargetOfficeVersion -and $manifest.Version -ne $Options.TargetOfficeVersion) { throw 'Cached Office build does not match the Windows 10 target.' }
|
||||
$names = @('ODT', 'odt.exe') + @(Get-OfficeCompanionDownloads -InstallTeams $Options.InstallTeams | ForEach-Object { $_.File })
|
||||
foreach ($entry in $manifest.Files) {
|
||||
if ([IO.Path]::IsPathRooted($entry.Path) -or $entry.Path -match '(^|[\\/])\.\.([\\/]|$)' -or ($entry.Path -split '[\\/]')[0] -notin $names) { throw 'Invalid cached file path.' }
|
||||
$path = Join-Path $candidate.FullName $entry.Path
|
||||
Assert-OfficeManagedPath $candidate.FullName $path
|
||||
$file = Get-Item -LiteralPath $path -ErrorAction Stop
|
||||
if ($file.Length -ne $entry.Length -or (Get-FileHash -LiteralPath $path -Algorithm SHA256 -ErrorAction Stop).Hash -ne $entry.Hash) { throw "Cached file changed: $path" }
|
||||
if ($file.PSIsContainer -or $file.Length -ne $entry.Length) { throw "Cached file is incomplete: $path" }
|
||||
}
|
||||
# Verify every executable we will launch, in addition to the cached hashes.
|
||||
# Keep publisher checks on executable installers; do not hash the Office payload.
|
||||
foreach ($name in @('odt.exe', 'ODT\setup.exe') + @(Get-OfficeCompanionDownloads -InstallTeams $Options.InstallTeams | ForEach-Object { $_.File })) {
|
||||
Assert-OfficeMicrosoftSignature (Join-Path $candidate.FullName $name)
|
||||
}
|
||||
@@ -477,6 +515,15 @@ function Initialize-OfficeMedia {
|
||||
param($Options, [string]$Workspace)
|
||||
$definitions = Get-OfficeDeploymentDefinitions
|
||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||
$Options.TargetOfficeVersion = ''
|
||||
if ($Options.OfficeFeatureRelease) {
|
||||
$historyPath = Join-Path $Workspace 'office-release-history.html'
|
||||
Save-OfficeDownload $definitions.OfficeReleaseHistory $historyPath
|
||||
$Options.TargetOfficeVersion = Get-OfficeBuildFromHistory (Get-Content -LiteralPath $historyPath -Raw -ErrorAction Stop) $Options.UpdateChannel $Options.OfficeFeatureRelease
|
||||
$null = Write-Output "Windows 10: selecting Office $($Options.OfficeFeatureRelease), build $($Options.TargetOfficeVersion), from Microsoft's $($Options.UpdateChannel) release history."
|
||||
} else {
|
||||
$null = Write-Output "ODT will select the latest available Office version in $($Options.UpdateChannel); no version is specified."
|
||||
}
|
||||
# Always refresh the small helper from this repository, even when using cached media.
|
||||
$helper = Join-Path $Workspace 'Office-UserCleanup.ps1'
|
||||
Save-OfficeDownload "$($definitions.RepositoryRoot)/resources/office/Office-UserCleanup.ps1" $helper
|
||||
@@ -487,7 +534,7 @@ function Initialize-OfficeMedia {
|
||||
if ($cached) {
|
||||
$odtFolder = Join-Path $Workspace 'ODT'
|
||||
$configPath = Join-Path $Workspace 'install.xml'; $removalPath = Join-Path $Workspace 'remove.xml'
|
||||
$config = New-OfficeConfiguration $Options $odtFolder $cached.Version; $config.Save($configPath)
|
||||
$config = New-OfficeConfiguration $Options $odtFolder $Options.TargetOfficeVersion; $config.Save($configPath)
|
||||
$removal = New-OfficeRemovalConfiguration $Options; $removal.Save($removalPath)
|
||||
$companions = @{}
|
||||
foreach ($download in (Get-OfficeCompanionDownloads -InstallTeams $Options.InstallTeams)) { $companions[$download.Name] = Join-Path $Workspace $download.File }
|
||||
@@ -509,7 +556,7 @@ function Initialize-OfficeMedia {
|
||||
$removalPath = Join-Path $Workspace 'remove.xml'
|
||||
$removal = New-OfficeRemovalConfiguration $Options; $removal.Save($removalPath)
|
||||
$configPath = Join-Path $Workspace 'install.xml'
|
||||
$config = New-OfficeConfiguration $Options $odtFolder; $config.Save($configPath)
|
||||
$config = New-OfficeConfiguration $Options $odtFolder $Options.TargetOfficeVersion; $config.Save($configPath)
|
||||
$null = Write-Output 'Downloading Office installation files before removing installed apps.'
|
||||
for ($attempt = 1; $attempt -le $definitions.DownloadAttempts; $attempt++) {
|
||||
$prefix = if ($attempt -eq 1) { 'office-download' } else { "office-download.retry-$attempt" }
|
||||
@@ -521,11 +568,11 @@ function Initialize-OfficeMedia {
|
||||
if ($code -ne 0) { throw "Office download failed ($code). Existing Office has not been removed." }
|
||||
$versions = @(Get-ChildItem -LiteralPath (Join-Path $odtFolder 'Office\Data') -Directory -ErrorAction Stop | Where-Object { $_.Name -match $definitions.OfficeBuildPattern })
|
||||
if ($versions.Count -ne 1) { throw 'Office download did not produce one identifiable build.' }
|
||||
if ($Options.TargetOfficeVersion -and $versions[0].Name -ne $Options.TargetOfficeVersion) { throw 'Downloaded Office build does not match the Windows 10 target. Existing Office has not been removed.' }
|
||||
$arch = if ($Options.OfficeArchitecture -eq '64') { 'x64' } else { 'x86' }
|
||||
foreach ($stream in @("stream.$arch.x-none.dat", "stream.$arch.$($definitions.Language).dat")) {
|
||||
if ((Get-Item -LiteralPath (Join-Path $versions[0].FullName $stream) -ErrorAction Stop).Length -eq 0) { throw "Office payload is empty: $stream" }
|
||||
}
|
||||
$config.Configuration.Add.SetAttribute('Version', $versions[0].Name); $config.Save($configPath)
|
||||
$companions = Initialize-OfficeCompanionMedia $Workspace -InstallTeams $Options.InstallTeams
|
||||
$media = [pscustomobject]@{ Setup = $setup; RemovalConfig = $removalPath; Config = $configPath; Helper = $helper; Version = $versions[0].Name; Companions = $companions; CachedMediaReused=$false }
|
||||
Save-OfficeMediaCache $Options $media $Workspace
|
||||
@@ -945,9 +992,17 @@ function Install-OfficeMedia {
|
||||
$key = 'HKLM:\SOFTWARE\Microsoft\Office\ClickToRun\Configuration'
|
||||
if (!(Test-Path -LiteralPath $key -ErrorAction Stop)) { return $false }
|
||||
$installed = Get-ItemProperty -LiteralPath $key -ErrorAction Stop
|
||||
$Options.ProductId -in ($installed.ProductReleaseIds -split ',') -and $installed.Platform -eq $platform -and $installed.VersionToReport -eq $Media.Version
|
||||
if ($Options.ProductId -notin ($installed.ProductReleaseIds -split ',') -or $installed.Platform -ne $platform -or $installed.VersionToReport -notmatch (Get-OfficeDeploymentDefinitions).OfficeBuildPattern) { return $false }
|
||||
# Unpinned ODT can install a newer build than the earlier validation download.
|
||||
# Windows 10 must still match its explicitly selected compatible build.
|
||||
if ($Options.TargetOfficeVersion) {
|
||||
if ($installed.VersionToReport -ne $Options.TargetOfficeVersion) { return $false }
|
||||
} elseif ([version]$installed.VersionToReport -lt [version]$Media.Version) { return $false }
|
||||
$installed.VersionToReport
|
||||
} 'the selected Office product, architecture, and version'
|
||||
if (!$verified) { throw 'Setup exited successfully but the installed product, architecture, or version did not match.' }
|
||||
$Media.Version = [string]$verified
|
||||
$null = Write-Output "Verified installed Office $($Media.Version) ($($Options.ProductId), $platform)."
|
||||
# Microsoft requires a restart to finish MSI removal even when setup doesn't enforce it.
|
||||
if ($msi.Count) { $null = Write-Output 'Legacy MSI Office removal was verified. A restart is required to finish removal; no automatic reboot was requested.'; return 3010 }
|
||||
$code
|
||||
|
||||
@@ -62,13 +62,17 @@ Business Basic, E1, frontline/web-only plans, education/government variants, con
|
||||
|
||||
With `ValidateBeforeChanges=true`, the script checks the subscription/activation combination, host and OS prerequisites, running apps, and availability of registered user profiles. It downloads and verifies ODT, the user cleanup helper, the full Office payload, and the selected companion bootstrappers. It writes the installation/removal XML and options, and returns `ValidationPassed` with `OfficeRemovalMethod=SilentODT`, the selected product, version, company, Teams choice, existing Office inventory, and running apps. It does **not** close apps, uninstall, clear identity/credentials, load user hives, register per-user cleanup tasks, or install apps. `OfficeAppShutdown=Force` only reports running apps in this mode; `Abort` fails validation if any are running.
|
||||
|
||||
Validation writes logs and staging files in the execution account's temp directory, secures its workspace, and runs ODT extraction and `/download` when no reusable cache exists; it is not a zero-write inventory scan. Allow several GB for the first run. It registers no scheduled tasks. A later `false` run repeats prerequisites and reuses matching, unexpired media after verifying its SHA-256 hashes and Microsoft executable signatures. The small user cleanup helper is always refreshed from the repository and is deleted from the validation workspace before returning. Validation does not prove tenant entitlements, successful future uninstallation/activation, or availability of the online companion payloads at install time.
|
||||
Validation writes logs and staging files in the execution account's temp directory, secures its workspace, and runs ODT extraction and `/download` when no reusable cache exists; it is not a zero-write inventory scan. Allow several GB for the first run. It registers no scheduled tasks. A later `false` run repeats prerequisites and reuses matching, unexpired media after checking its file inventory, sizes, and Microsoft executable signatures. The script does not calculate or compare file checksums. The small user cleanup helper is always refreshed from the repository and is deleted from the validation workspace before returning. Validation does not prove tenant entitlements, successful future uninstallation/activation, or availability of the online companion payloads at install time.
|
||||
|
||||
The script resolves the current versioned ODT download from the [Microsoft Download Center](https://www.microsoft.com/en-us/download/details.aspx?id=49117). It does not depend on the Emberkom-hosted setup.exe or a frozen Microsoft binary URL. If the page format changes, it stops before removal. The downloaded ODT package and extracted setup.exe must have valid Microsoft signatures.
|
||||
|
||||
**Unattended deployment does not download or launch Get Help.** The Get Help build observed on October 14, 2026 created an elevated PowerShell cleanup window in the logged-in user's session even when its parent ran hidden under SYSTEM. Hiding the parent did not hide that child, and Microsoft's documented `-HideProgress` option applies to other scenarios, not Office removal. See the [Get Help command-line reference](https://learn.microsoft.com/en-us/troubleshoot/microsoft-365/admin/miscellaneous/get-help-command-line-overview). The script uses ODT's supported silent removal instead; an interactive scrub is an attended troubleshooting step only.
|
||||
|
||||
On a cache miss, ODT downloads the current build in the selected channel. A cache hit uses the build validated earlier, for at most seven days from the original download; it does not check for a newer build during that interval. Installation is pinned to that local build, uses English (`en-us`), enables updates, and uses `Display Level="None"`. The [ODT configuration reference](https://learn.microsoft.com/en-us/microsoft-365-apps/deploy/office-deployment-tool-configuration-options) describes these settings. Existing update policies can subsequently override the chosen channel.
|
||||
On Windows 11, the download and installation XML omit `Version`, letting ODT select the latest available build in the selected channel. Matching staged media can be reused for seven days; ODT may fetch newer files at installation time if the channel has advanced. Verification accepts the staged build or a newer build and reports the actual installed version. There is no fixed build number to maintain.
|
||||
|
||||
Windows 10 is the exception: Microsoft limits it to [Office feature release 2608 with subsequent security updates](https://learn.microsoft.com/en-us/microsoft-365-apps/end-of-support/windows-10-support). Before using any cache or removing apps, the script resolves the highest published 2608 build for the selected channel from [Microsoft's release history](https://learn.microsoft.com/en-us/officeupdates/update-history-microsoft365-apps-by-date). Only Windows 10 specifies that build in the download/install XML. A new published build makes older cached media ineligible. Missing release data or a mismatched download stops staging before removal. The feature release and history/channel definitions are centralized at the top of the script; patch build numbers are not hardcoded. Server editions are not classified as Windows 10 by their build number.
|
||||
|
||||
Installation uses English (`en-us`), enables updates, and uses `Display Level="None"`. No `Updates TargetVersion` is set, so installation selection does not freeze future updates. The [ODT configuration reference](https://learn.microsoft.com/en-us/microsoft-365-apps/deploy/office-deployment-tool-configuration-options) describes these settings. Existing update policies can subsequently override the chosen channel.
|
||||
|
||||
The companion apps remain excluded from ODT because the main script installs the selected companions explicitly for all users after Office. Their installers are downloaded from Microsoft's evergreen links and their Microsoft Authenticode signatures checked before any removal; Teams is staged only when the subscription includes it. Teams, new Outlook, and WebView2 use online bootstrappers: only their installer executables are staged, and their payload downloads can still fail later. The complete Office suite payload is staged before removal.
|
||||
|
||||
@@ -128,9 +132,9 @@ The helper, lock, and reinstall marker for these previously agreed logon tasks l
|
||||
|
||||
## Temporary media and cleanup during deployment
|
||||
|
||||
- A completed staging pass records a protected `media-cache.json` inventory with file hashes, version, original creation time, and a matching key derived from product, architecture, channel, language, and companion download definitions. Compatible runs move these installers into their new workspace instead of copying or redownloading them. This keeps each deployment's user cleanup ID separate. Company, activation, shutdown, and reboot selections are applied to freshly generated XML. The receipt reports `CachedMediaReused`.
|
||||
- A completed staging pass records a protected `media-cache.json` inventory with file sizes, version, original creation time, and matching product, architecture, channel, language, Windows 10 target (when applicable), and companion download definitions. Compatible runs move these installers into their new workspace instead of copying or redownloading them. This keeps each deployment's user cleanup ID separate. Company, activation, shutdown, and reboot selections are applied to freshly generated XML. The receipt reports `CachedMediaReused`. The new cache format refreshes caches created by older script versions once; subsequent matching validation/deployment runs reuse them normally.
|
||||
- Downloads live under `EmberkomOfficeDeployment\<deployment-id>` in `[IO.Path]::GetTempPath()` for the execution account. In Syncro this is SYSTEM's temp location, not the signed-in user's temp directory. The actual path is reported in `Workspace`. Folder permissions prevent standard users from changing executable content.
|
||||
- Cached installers remain eligible for reuse for **seven days**, provided the files still exist. This is a freshness limit, not a scheduled deletion policy. Expired, incomplete, modified, unsigned, or incompatible caches are not reused. Changing to a no-Teams plan cannot reuse a Teams-enabled cache. A failed deployment or a stop for restart leaves media in temp for a retry. Repeated validation does not extend the original freshness limit. If routine temp cleanup purges it first, the next run downloads fresh media.
|
||||
- Cached installers remain eligible for reuse for **seven days**, provided the files still exist. This is a freshness limit, not a scheduled deletion policy. Expired, incomplete, unsigned, or incompatible caches are not reused. Size checks detect truncation, not same-size payload changes; the script leaves payload integrity checking to Microsoft's installer. Changing to a no-Teams plan cannot reuse a Teams-enabled cache. A failed deployment or a stop for restart leaves media in temp for a retry. Repeated validation does not extend the original freshness limit. If routine temp cleanup purges it first, the next run downloads fresh media.
|
||||
- Once Office and all selected companion apps are verified installed, the same script run deletes its entire temporary workspace, including the Office payload, ODT package/extraction, companion bootstrappers, cache manifest, helper copy, generated XML, and temporary process logs. It also removes unused older temporary deployment workspaces and known installer downloads from older ProgramData stages. Deferred-user files in ProgramData, installed applications, and Microsoft's servicing caches are preserved.
|
||||
- There is **no daily housekeeping task, resident housekeeping script, or separate log-retention job**. Validation/failure leftovers are subject to the endpoint's existing temp-cleanup routines; exact deletion timing depends on those routines. File removal rejects junctions/symlinks and skips workspaces referenced by running processes.
|
||||
- Cleanup failures do not change a verified installation into an installation failure. `ArtifactCleanupPending=true` and a console warning identify files left behind; there is no scheduled retry. A later successful deployment or the endpoint's ordinary temp cleanup can remove them.
|
||||
|
||||
@@ -36,6 +36,7 @@ try {
|
||||
}
|
||||
# Exercise the real bounded retry loops without delaying offline tests.
|
||||
function Start-Sleep { param([int]$Seconds) $script:testSleeps += $Seconds }
|
||||
function Get-FileHash { throw 'Office deployment must not scan file checksums.' }
|
||||
$script:testSleeps = @()
|
||||
& {
|
||||
$script:probeCalls=0; $script:testSleeps=@()
|
||||
@@ -221,7 +222,29 @@ try {
|
||||
Assert-OfficeTest ($null -ne $roundTrip.SelectSingleNode('/Configuration/RemoveMSI') -and $null -ne $roundTrip.SelectSingleNode('/Configuration/Add')) 'Legacy MSI removal must run with the replacement installation.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Add.OfficeClientEdition -eq '32') '32-bit selection ignored.'
|
||||
Assert-OfficeTest ($roundTrip.SelectSingleNode('//Property[@Name="SharedComputerLicensing"]').Value -eq '1') 'Shared activation lost.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Add.Version -eq '16.0.12345.67890') 'Downloaded version must be pinned.'
|
||||
Assert-OfficeTest ($roundTrip.Configuration.Add.Version -eq '16.0.12345.67890') 'An explicitly selected Windows 10 build must be retained.'
|
||||
$latestXml = New-OfficeConfiguration $options 'C:\Office'
|
||||
Assert-OfficeTest (!$latestXml.Configuration.Add.HasAttribute('Version')) 'Ordinary deployments must let ODT select the latest version.'
|
||||
Assert-OfficeTest (!$roundTrip.Configuration.Updates.HasAttribute('TargetVersion') -and $roundTrip.Configuration.Updates.Enabled -eq 'TRUE') 'Installation selection must not freeze future Office updates.'
|
||||
Assert-OfficeTest ((Get-OfficeFeatureRelease -Build 19045 -ProductType 1) -eq '2608') 'Windows 10 must select feature release 2608.'
|
||||
Assert-OfficeTest ((Get-OfficeFeatureRelease -Build 22631 -ProductType 1) -eq '') 'Windows 11 must remain unpinned.'
|
||||
Assert-OfficeTest ((Get-OfficeFeatureRelease -Build 20348 -ProductType 3) -eq '') 'Windows Server must not be mistaken for Windows 10.'
|
||||
$releaseHistory = @'
|
||||
<a href="current-channel#version-2608-september-18">Version 2608 (Build 20326.20158)</a>
|
||||
<a href="current-channel#version-2608-september-08">Version 2608 (Build 20326.20144)</a>
|
||||
<a href="monthly-enterprise-channel#version-2608-october-13">Version 2608 (Build 20326.20232)</a>
|
||||
<a href="semi-annual-enterprise-channel#version-2608-october-13">Version 2608 (Build 20326.20230)</a>
|
||||
<a href="current-channel#version-2610-october-21">Version 2610 (Build 20527.20088)</a>
|
||||
<a href="current-channel-preview#version-2608-fixture">Version 2608 (Build 20326.99999)</a>
|
||||
'@
|
||||
foreach ($channel in @('Current','MonthlyEnterprise','SemiAnnual')) {
|
||||
$expectedBuild = @{Current='16.0.20326.20158'; MonthlyEnterprise='16.0.20326.20232'; SemiAnnual='16.0.20326.20230'}[$channel]
|
||||
Assert-OfficeTest ((Get-OfficeBuildFromHistory $releaseHistory $channel '2608') -eq $expectedBuild) "Wrong Windows 10 build selected for $channel."
|
||||
}
|
||||
$numericHistory = '<a href="https://learn.microsoft.com/en-us/officeupdates/current-channel#version-2608-fixture">Version 2608 (Build 20326.9)</a><a href=''current-channel#version-2608-fixture''><span>Version 2608 (Build 20326.10)</span></a>'
|
||||
Assert-OfficeTest ((Get-OfficeBuildFromHistory $numericHistory Current '2608') -eq '16.0.20326.10') 'Build sorting must be numeric and tolerate HTML formatting.'
|
||||
Assert-OfficeThrows { Get-OfficeBuildFromHistory '<html>Changed Microsoft page</html>' Current '2608' } 'did not identify.*Existing Office has not been removed'
|
||||
Assert-OfficeThrows { Get-OfficeBuildFromHistory $releaseHistory Invalid '2608' } 'Invalid.*selection'
|
||||
foreach ($app in @('OneDrive','Groove','Teams','OutlookForWindows')) { Assert-OfficeTest ($app -in $roundTrip.Configuration.Add.Product.ExcludeApp.ID) "ODT must leave $app to the explicit companion installation stage." }
|
||||
Assert-OfficeCompanionPlatform -Build 22631 -ProductType 1 -Revision 0 -EditionId Professional
|
||||
Assert-OfficeCompanionPlatform -Build 20348 -ProductType 3 -Revision 2402 -EditionId ServerStandard
|
||||
@@ -253,6 +276,9 @@ try {
|
||||
if ([IO.Path]::GetFileName($Path) -eq 'odt-download-page.html') {
|
||||
Assert-OfficeTest ($TimeoutSeconds -eq (Get-OfficeDeploymentDefinitions).OdtPageTimeoutSeconds) 'ODT page must use the retried downloader with its configured timeout.'
|
||||
[IO.File]::WriteAllText($Path, 'https://download.microsoft.com/test/officedeploymenttool_test.exe')
|
||||
} elseif ([IO.Path]::GetFileName($Path) -eq 'office-release-history.html') {
|
||||
Assert-OfficeTest ($Uri -eq (Get-OfficeDeploymentDefinitions).OfficeReleaseHistory) 'Windows 10 release lookup must use Microsoft history.'
|
||||
[IO.File]::WriteAllText($Path, $script:mediaHistory)
|
||||
} elseif ([IO.Path]::GetFileName($Path) -eq 'Office-UserCleanup.ps1') {
|
||||
[IO.File]::WriteAllText($Path, '# ' + (Get-OfficeDeploymentDefinitions).HelperVersion)
|
||||
} else {
|
||||
@@ -272,21 +298,44 @@ try {
|
||||
} elseif ([IO.Path]::GetFileName($FilePath) -eq 'setup.exe' -and $Arguments -like '/download *') {
|
||||
$script:mediaDownloadCalls++
|
||||
if ($script:mediaDownloadCalls -eq 1) { return 12029 }
|
||||
$payload = Join-Path $mediaWorkspace 'ODT\Office\Data\16.0.12345.67890'
|
||||
$downloadXml = [xml](Get-Content -LiteralPath (Join-Path $mediaWorkspace 'install.xml') -Raw)
|
||||
Assert-OfficeTest ($downloadXml.Configuration.Add.GetAttribute('Version') -eq $options.TargetOfficeVersion) 'The OS-specific build must be selected before downloading.'
|
||||
$payload = Join-Path $mediaWorkspace ('ODT\Office\Data\' + $script:mediaPayloadVersion)
|
||||
$null = [IO.Directory]::CreateDirectory($payload)
|
||||
foreach ($name in @('stream.x64.x-none.dat', 'stream.x64.en-us.dat')) { [IO.File]::WriteAllText((Join-Path $payload $name), 'Inert Office payload.') }
|
||||
} else { throw "Unexpected executable requested during staging: $FilePath $Arguments" }
|
||||
return 0
|
||||
}
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'}
|
||||
$script:mediaPayloadVersion = '16.0.12345.67890'
|
||||
$media = Initialize-OfficeMedia $options $mediaWorkspace
|
||||
Assert-OfficeTest ($media.Setup -in $script:mediaSignatures) 'Extracted ODT must still pass signature checks.'
|
||||
Assert-OfficeTest ($media.Version -eq '16.0.12345.67890' -and $media.Companions.Count -eq 3 -and !$media.Companions.ContainsKey('Teams')) 'Media staging lost its build or no-Teams selection.'
|
||||
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Staged configuration must pin the downloaded build.'
|
||||
Assert-OfficeTest (!([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.HasAttribute('Version')) 'Staging must not pin ordinary installations to the downloaded build.'
|
||||
Assert-OfficeTest (($script:mediaProcesses -join ',') -eq 'odt.exe,setup.exe,setup.exe') 'Staging must only extract ODT and download Office, with no removal or installation.'
|
||||
$removal = [xml](Get-Content -LiteralPath $media.RemovalConfig -Raw)
|
||||
Assert-OfficeTest ($removal.Configuration.Remove.All -eq 'TRUE' -and $removal.Configuration.Display.Level -eq 'None') 'Staging must save the silent removal configuration.'
|
||||
Assert-OfficeTest (!$media.Scrubber -and !($script:mediaSignatures -match 'GetHelp|SaRA')) 'Unattended deployments must not stage an interactive scrubber.'
|
||||
foreach ($mode in @('win10', 'incompatible-download', 'history-unavailable')) {
|
||||
$mediaWorkspace = Join-Path $testRoot $mode; $null = [IO.Directory]::CreateDirectory($mediaWorkspace)
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Standard'; OfficeArchitecture='64'}
|
||||
$options.OfficeFeatureRelease = Get-OfficeFeatureRelease -Build 19045 -ProductType 1
|
||||
$script:mediaProcesses = @(); $script:mediaDownloadCalls = 0
|
||||
$script:mediaHistory = $releaseHistory
|
||||
$script:mediaPayloadVersion = '16.0.20326.20158'
|
||||
if ($mode -eq 'history-unavailable') {
|
||||
$script:mediaHistory = '<html>No eligible build</html>'
|
||||
Assert-OfficeThrows { Initialize-OfficeMedia $options $mediaWorkspace } 'did not identify'
|
||||
Assert-OfficeTest (!$script:mediaProcesses.Count) 'Missing Windows 10 release data must stop before launching installers.'
|
||||
} elseif ($mode -eq 'incompatible-download') {
|
||||
$script:mediaPayloadVersion = '16.0.20527.20088'
|
||||
Assert-OfficeThrows { Initialize-OfficeMedia $options $mediaWorkspace } 'Downloaded Office build does not match the Windows 10 target'
|
||||
} else {
|
||||
$media = Initialize-OfficeMedia $options $mediaWorkspace
|
||||
Assert-OfficeTest ($media.Version -eq '16.0.20326.20158' -and $options.TargetOfficeVersion -eq $media.Version) 'Windows 10 must stage its compatible build.'
|
||||
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Windows 10 installation must retain the compatible target.'
|
||||
}
|
||||
}
|
||||
}
|
||||
& {
|
||||
$script:staged = @(); $script:verified = @()
|
||||
@@ -627,6 +676,15 @@ try {
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'did not match'
|
||||
$script:installed.Platform='x64'; $script:installed.VersionToReport='16.0.0.1'
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'did not match'
|
||||
$script:installed.VersionToReport='16.0.2.3'
|
||||
Assert-OfficeTest ((Install-OfficeMedia $options $media $testRoot) -eq 0 -and $media.Version -eq '16.0.2.3') 'A newer unpinned build must pass and report the actual installed version.'
|
||||
$options.TargetOfficeVersion='16.0.1.2'
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'did not match'
|
||||
$script:installed.VersionToReport='16.0.1.2'
|
||||
Assert-OfficeTest ((Install-OfficeMedia $options $media $testRoot) -eq 0 -and $media.Version -eq '16.0.1.2') 'Windows 10 must verify its explicitly selected build.'
|
||||
$options.TargetOfficeVersion=''
|
||||
$script:installed.VersionToReport='invalid'
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'did not match'
|
||||
$script:installCode=42
|
||||
Assert-OfficeThrows { Install-OfficeMedia $options $media $testRoot } 'installation failed'
|
||||
$script:installCode=0; $script:installed.VersionToReport='16.0.1.2'; $script:officeChecks=0
|
||||
@@ -695,7 +753,7 @@ try {
|
||||
Assert-OfficeTest ((Get-Content -LiteralPath $Global:LogFile -Raw) -match 'Error: User cleanup task registration failed for unmapped \(C:\\Users\\defaultuser100000\)') 'Registration failures must reach the Tools diagnostic log.'
|
||||
}
|
||||
|
||||
# Real temporary files for cache reuse/tampering; no installer or network may run.
|
||||
# Real temporary files for cache reuse/completeness; no installer or network may run.
|
||||
& {
|
||||
$cacheRoot = Join-Path $testRoot 'cache-tests'; $null = [IO.Directory]::CreateDirectory($cacheRoot)
|
||||
$source = Join-Path $cacheRoot ('a' * 32); $null = [IO.Directory]::CreateDirectory($source)
|
||||
@@ -710,17 +768,27 @@ try {
|
||||
function Invoke-OfficeProcess { throw 'A cached deployment must not redownload Office.' }
|
||||
$manifestPath = Join-Path $source 'media-cache.json'
|
||||
$originalManifest = Get-Content -LiteralPath $manifestPath -Raw
|
||||
Assert-OfficeTest (!($originalManifest | ConvertFrom-Json).Files[0].PSObject.Properties['Hash']) 'Cache manifests must not store file checksums.'
|
||||
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5'; OfficeArchitecture='64'}
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'Teams selection mismatch reused the wrong cache.'
|
||||
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'; UpdateChannel='MonthlyEnterprise'}
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'Channel mismatch reused the wrong cache.'
|
||||
$different = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft/Office 365 E3/E5 (no Teams)'; OfficeArchitecture='64'}
|
||||
$different.TargetOfficeVersion='16.0.20326.20158'
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'A Windows 10 target reused incompatible unpinned media.'
|
||||
$manifest = $originalManifest | ConvertFrom-Json; $manifest.Key = Get-OfficeMediaCacheKey $different
|
||||
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $different $target)) 'A matching cache key hid an incompatible Windows 10 payload version.'
|
||||
$manifest = $originalManifest | ConvertFrom-Json; $manifest.Schema = 1
|
||||
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Old cache manifests must be refreshed under the new version-selection contract.'
|
||||
$manifest = $originalManifest | ConvertFrom-Json; $manifest.CreatedUtc = [DateTime]::UtcNow.AddDays(-8).ToString('o')
|
||||
$manifest | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath $manifestPath
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Expired cache was reused.'
|
||||
Set-Content -LiteralPath $manifestPath -Value $originalManifest
|
||||
$stream = Join-Path $source 'ODT\Office\Data\16.0.12345.67890\stream.x64.x-none.dat'
|
||||
$originalBytes = [IO.File]::ReadAllBytes($stream); $changedBytes = $originalBytes.Clone(); $changedBytes[0] = $changedBytes[0] -bxor 1; [IO.File]::WriteAllBytes($stream, $changedBytes)
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Same-size payload corruption passed hash verification.'
|
||||
$originalBytes = [IO.File]::ReadAllBytes($stream); [IO.File]::WriteAllText($stream, '')
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Truncated cached media passed the basic size check.'
|
||||
[IO.File]::WriteAllBytes($stream, $originalBytes)
|
||||
$extra = Join-Path $source 'ODT\unexpected.dll'; Set-Content -LiteralPath $extra -Value 'unexpected dependency'
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Unrecorded executable dependencies passed cache verification.'
|
||||
@@ -732,14 +800,35 @@ try {
|
||||
$script:rejectCacheSignature = $true
|
||||
Assert-OfficeTest (!(Restore-OfficeMediaCache $options $target)) 'Invalid Microsoft signature was reused.'
|
||||
$script:rejectCacheSignature = $false
|
||||
# Same-size contents are deliberately not hashed; ODT services the payload.
|
||||
$changedBytes = $originalBytes.Clone(); $changedBytes[0] = $changedBytes[0] -bxor 1; [IO.File]::WriteAllBytes($stream, $changedBytes)
|
||||
$media = Initialize-OfficeMedia $options $target
|
||||
Assert-OfficeTest ($media.CachedMediaReused -and $media.Version -eq '16.0.12345.67890' -and $script:helperDownloads -eq 1) 'Deployment did not reuse the validated media and refresh the helper.'
|
||||
Assert-OfficeTest (!(Test-Path -LiteralPath (Join-Path $source 'ODT')) -and (Test-Path -LiteralPath $media.Setup)) 'Cache transfer duplicated large files or lost setup.'
|
||||
$config = [xml](Get-Content -LiteralPath $media.Config -Raw)
|
||||
Assert-OfficeTest ($config.Configuration.AppSettings.Setup.Value -eq 'New Company' -and $config.Configuration.Add.SourcePath -eq (Join-Path $target 'ODT')) 'Reused media retained stale company/configuration paths.'
|
||||
Assert-OfficeTest (!$config.Configuration.Add.HasAttribute('Version')) 'Reusing ordinary media must not pin the installation version.'
|
||||
Assert-OfficeTest ((Get-Content -LiteralPath (Join-Path $target 'media-cache.json') -Raw | ConvertFrom-Json).CreatedUtc -eq ($originalManifest | ConvertFrom-Json).CreatedUtc) 'Reuse extended cache expiry.'
|
||||
Assert-OfficeThrows { Remove-OfficeManagedItem $cacheRoot $testRoot } 'outside the Office deployment root'
|
||||
Assert-OfficeThrows { Remove-OfficeManagedItem $cacheRoot $cacheRoot } 'outside the Office deployment root'
|
||||
|
||||
# Windows 10 refreshes only the small release history and helper on a compatible hit.
|
||||
$win10Source = Join-Path $cacheRoot ('c' * 32); $null = [IO.Directory]::CreateDirectory($win10Source)
|
||||
foreach ($file in Get-ChildItem -LiteralPath (Join-Path $testRoot 'win10')) { Copy-Item -LiteralPath $file.FullName -Destination $win10Source -Recurse }
|
||||
$win10Target = Join-Path $cacheRoot ('d' * 32); $null = [IO.Directory]::CreateDirectory($win10Target)
|
||||
$options = Get-OfficeDeploymentOptions @{OfficeSubscription='Microsoft 365 Business Standard'; OfficeArchitecture='64'}
|
||||
$options.OfficeFeatureRelease = Get-OfficeFeatureRelease -Build 19045 -ProductType 1
|
||||
function Save-OfficeDownload {
|
||||
param($Uri,$Path)
|
||||
switch ([IO.Path]::GetFileName($Path)) {
|
||||
'office-release-history.html' { [IO.File]::WriteAllText($Path, $releaseHistory) }
|
||||
'Office-UserCleanup.ps1' { [IO.File]::WriteAllText($Path, '# ' + (Get-OfficeDeploymentDefinitions).HelperVersion) }
|
||||
default { throw 'Unexpected installer download on Windows 10 cache hit' }
|
||||
}
|
||||
}
|
||||
$media = Initialize-OfficeMedia $options $win10Target
|
||||
Assert-OfficeTest ($media.CachedMediaReused -and $media.Version -eq '16.0.20326.20158') 'Windows 10 did not reuse compatible validated media.'
|
||||
Assert-OfficeTest (([xml](Get-Content -LiteralPath $media.Config -Raw)).Configuration.Add.Version -eq $media.Version) 'Reused Windows 10 media lost its compatible version constraint.'
|
||||
}
|
||||
# Cleanup runs synchronously on success. Downloads are temporary; pending-user
|
||||
# helpers have a separate durable folder and are never part of the media cache.
|
||||
|
||||
Reference in New Issue
Block a user