26 KiB
Microsoft 365 clean deployment through Syncro
The script defaults to validation only. Set ValidateBeforeChanges=false explicitly to enable a destructive replacement of the Office installation. Deployment removes the Office suite, Visio, Project, separate Teams installations, OneDrive, and new Outlook, then silently installs the selected Microsoft 365 desktop suite, new Outlook and OneDrive, plus current Teams only when the selected subscription includes Teams. Classic Outlook is included alongside new Outlook. Visio and Project are not reinstalled. User documents, Outlook PST/OST files, and OneDrive sync folders are not deliberately deleted. Per-user cleanup for absent users has the boundaries described below.
The selection identifies the client's purchased subscription; it does not discover tenant licenses, purchase a license, or assign one. The user still needs a matching assigned license. Windows work-account sign-in is preserved, so Windows SSO can sign Office in again.
Publish and configure
- Publish
Install-MicrosoftOffice365.ps1andresources/office/Office-UserCleanup.ps1together in the public repository. The installer requires helper versionEmberkomOfficeUserCleanup-v3, which handles per-user Teams add-ins advertised in HKLM and protects reinstalled apps from deferred cleanup. The existingTools.ps1is used unchanged. Nothing in this change publishes itself. - Paste/upload rmm/Install-MicrosoftOffice365.ps1 as the Syncro Windows PowerShell 5.1 script. Select Run As: System. PowerShell 7 is not required or launched. Allow a generous maximum runtime, initially 180 minutes, and enough disk space for both the download and installation. A clean deployment downloads several GB per endpoint and requires internet access throughout companion app installation.
- Use Add Script Variable, type Dropdown, then Edit Dropdown Values for each variable below. Enter names without
$. Syncro stores dropdown definitions separately; uploading a.ps1does not create them. See Syncro's script editor documentation. - First run with
ValidateBeforeChanges=trueand review the result. To deploy, rerun withfalseduring the maintenance window. Pilot on a disposable VM with representative Office, user profiles, and companion apps. Then run against the intended endpoint or asset selection. Group endpoints by subscription and architecture so each run's selections apply correctly.
| Variable | Exact dropdown values | Default |
|---|---|---|
ValidateBeforeChanges |
true, false |
true (validate only; false enables removal/reinstallation) |
OfficeSubscription |
Use the subscription list below, plus Select a subscription |
Select a subscription (deliberately rejected until changed) |
OfficeArchitecture |
Auto, 64, 32 |
Auto |
UpdateChannel |
Current, MonthlyEnterprise, SemiAnnual |
Current |
OfficeActivation |
User, SharedComputer |
User |
OfficeAppShutdown |
Abort, Force |
Abort |
All variables configured in Syncro must have a nonempty value. Set the dropdown defaults above in Syncro; the shim reads the injected strings without assigning over them. Select a subscription is a nonempty placeholder that the main script rejects before deployment.
ValidateBeforeChanges uses the existing ConvertTo-RmmBoolean helper from Tools.ps1. Missing, null, or blank input defaults to true; invalid text fails. The workload requires a parsed Boolean, preventing an omitted or unparsed value from enabling changes. false still performs prerequisite and download validation before cleanup. It does not skip those checks.
Syncro supplies COMPANY automatically with the endpoint's company name in this environment. Preserve that existing mapping; no company dropdown is needed. The shim passes it through to the main script, which includes <AppSettings><Setup Name="Company" Value="..." /></AppSettings> in the ODT configuration, retaining the original installer's company setting. Outside Syncro, a missing value (or None) omits this setting. No product key, password, or tenant credentials are needed in Syncro.
Abort stops if an Office app, Teams, OneDrive, or new Outlook is running. Force closes them across all sessions after staging succeeds; unsaved work can be lost. Choose Force only for the intended maintenance window. Deferred cleanup also closes that user's classic Teams when removing it at sign-in.
Auto selects 64-bit Office on 64-bit Windows and 32-bit otherwise. Select 32 only for required add-in compatibility on supported x86/x64 systems. ARM64 rejects 32-bit Office. Companion installers follow the Windows architecture independently of Office bitness. The main repository script relaunches a 32-bit Syncro host into native Windows PowerShell 5.1 via Sysnative on 64-bit Windows, preserving the injected strings. All scheduled user cleanup also uses powershell.exe. The RMM shim contains no deployment or relaunch logic.
Before removal, the script checks the apps' minimum OS requirements: Windows build 19041 or newer; Windows Server requires at least 2022 build 20348.2402 for new Outlook. Windows 10 LTSC is rejected when Teams is selected. These checks do not replace checking current Office/Windows support and the additional requirements of an RDS/AVD deployment.
Subscription choices
Copy these exact names into the OfficeSubscription dropdown. The mapping follows Microsoft's ODT product ID table.
| Subscription | ODT product |
|---|---|
| Microsoft 365 Business Standard | O365BusinessRetail |
| Microsoft 365 Business Premium | O365BusinessRetail |
| Microsoft 365 Apps for business | O365BusinessEEANoTeamsRetail |
| Microsoft 365 Business Standard (no Teams) | O365BusinessEEANoTeamsRetail |
| Microsoft 365 Business Premium (no Teams) | O365BusinessEEANoTeamsRetail |
| Microsoft 365 Apps for enterprise | O365ProPlusEEANoTeamsRetail |
| Microsoft/Office 365 E3/E5 | O365ProPlusRetail |
| Microsoft/Office 365 E3/E5 (no Teams) | O365ProPlusEEANoTeamsRetail |
The E3/E5 selections are consolidated because those plans use the same Office product and shared-computer activation validation. Their other subscription features do not change this installer. The previously documented individual E3/E5 names remain accepted as aliases for saved selections, but only the two combined names are needed in the dropdown. Business Standard and Premium remain separate because their shared-computer activation eligibility differs.
All selections install new Outlook and OneDrive. Teams is downloaded and installed only for Microsoft 365 Business Standard, Microsoft 365 Business Premium, and Microsoft/Office 365 E3/E5 (including their accepted legacy enterprise aliases). Every (no Teams) selection and both standalone Microsoft 365 Apps for business / Microsoft 365 Apps for enterprise selections skip the Teams download, installation, and installed-version verification. ODT also explicitly excludes Teams, so it cannot bypass this selection. Existing Teams installations are still removed during cleanup. Installing a client does not purchase/assign service entitlements; users must have the appropriate account and services to use it.
Business Basic, E1, frontline/web-only plans, education/government variants, consumer subscriptions, and perpetual Office/LTSC editions are not deployment selections in this script. Missing or unsupported selections stop before downloads or removal. Existing perpetual Office installations can be removed by the scrubber; that does not authorize installing Microsoft 365 without its license.
SharedComputer enables shared computer activation. Business Standard and standalone Apps for business are rejected for this mode; Business Premium and the listed eligible enterprise plans are accepted. Confirm the users' entitlements and host support, especially on RDS/AVD. See Microsoft's shared activation requirements.
Download, removal, and installation
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, Get Help, the user cleanup helper, the full Office payload, and the selected companion bootstrappers. It writes the XML/options and returns ValidationPassed with 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 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, secures its workspace, and runs ODT extraction and /download; it is not a zero-write inventory scan. Allow several GB and the same download time as deployment. A later false run downloads fresh media and repeats the checks. 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. 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.
The Get Help command-line package is downloaded fresh and its executable signature checked. Microsoft's evergreen link still uses the historical name https://aka.ms/SaRA_EnterpriseVersionFiles. The script executes GetHelpCmd.exe, not retired SaRAcmd.exe. During staging (including validation-only runs), it runs only the read-only -? usage command to verify the downloaded tool's command syntax; this does not start an uninstall scenario. Usage output is retained in gethelp-usage.stdout.log / .stderr.log.
ODT downloads the current build in the selected channel first. Installation is pinned to that local build, uses English (en-us), enables updates, and uses Display Level="None". The ODT configuration reference 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.
| Component | Silent deployment | Verification |
|---|---|---|
| WebView2 runtime, if missing machine-wide | MicrosoftEdgeWebview2Setup.exe /silent /install |
Machine runtime version registration |
| OneDrive | OneDriveSetup.exe /allusers /silent |
Machine version registration and Microsoft-signed executable under Program Files |
| Teams, when included in the subscription | teamsbootstrapper.exe -p |
MSTeams provisioned package |
| New Outlook | OutlookSetup.exe --provision true --quiet --start- |
Microsoft.OutlookForWindows provisioned package |
These follow Microsoft's deployment guidance for Teams, new Outlook, OneDrive per-machine installation, and WebView2. Although the Outlook instructions show a PowerShell 7 shell, the command invokes a native executable; this script passes its arguments through Start-Process in Windows PowerShell 5.1. No pwsh, winget, or interactive Store sign-in is used. The existing evergreen WebView2 runtime, when present, retains its normal update mechanism.
New Outlook, and Teams when selected, are provisioned for current and future users; users may need to sign out and back in for registration. OneDrive installs per-machine and handles migration of existing user accounts. App account setup and any tenant policy prompts are separate from the silent installation. The script does not switch the default mail application, force migration from classic Outlook, or configure OneDrive folder backup.
Removal uses Get Help's OfficeScrubScenario, plus separate targeted Appx/provisioned-package and Teams/OneDrive uninstall operations. The script adds -OfficeVersion All only when the downloaded tool's usage advertises that switch. The Microsoft-signed build inspected on October 14, 2026 (1.0.0+d28f675) rejects it despite Microsoft's documentation; that build internally sets officeVersion=All when invoked as GetHelpCmd.exe -S OfficeScrubScenario -AcceptEula. The documented coverage spans Office 2007 through Microsoft 365/2024, but actual removal still depends on the downloaded tool's implementation and the endpoint's installation state. Corrupt, unsupported, orphaned, or unusually packaged installations may require manual repair; unknown uninstall commands and remaining detected Office products stop the deployment. No automatic reboot or resume task is created.
The script recognizes both the older numbered scenario results and the current Scenario completed successfully. message. A process exit of zero alone does not prove success: this Get Help build also returns zero for invalid arguments. Error text is logged and included in the Syncro failure message. When Get Help reports that uninstall is running in the background, the script polls for up to 30 minutes, requiring Office inventory to become empty and newly launched installer/script workers to exit, followed by a 60-second quiet interval. Existing unrelated consoles and idle installer service hosts do not block completion. This avoids immediately reinstalling after a background-launch acknowledgement. A timeout stops installation and reports remaining products/workers; do not launch another deployment over unfinished cleanup.
Transient failures get bounded recovery before deployment stops:
- HTTP downloads, including the ODT discovery page, get three attempts. ODT
/downloadalso gets three attempts using the same staging folder, before any app removal. An unrecognized discovery page, invalid signature, or invalid staged payload still fails validation. - Machine and per-user MSI removal retry Windows Installer's busy result,
1618, up to five attempts with 15 seconds between attempts. Other installer failure codes retain their existing handling. The script does not kill an unrelated installer or blindly repeat an Office installation or scrub. - After successful operations, machine removal and installation verification allow up to 60 seconds of polling for registry/package state to settle. The user's Teams add-in removal has the same allowance. Get Help's explicitly asynchronous removal uses the longer background wait described above. Reads that fail still raise an error; inaccessible state is not treated as proof that an app is gone.
- Appx removal checks whether the exact package disappeared even when the removal command reports an error. If it remains, removal retries up to three times, each followed by the verification wait. Installed and provisioned packages must both be absent before continuing.
- A process that exits just before forced shutdown is tolerated. Failure to unregister an already-completed cleanup task is logged and does not stop installation; its completion marker makes subsequent task runs a no-op.
Retries and waits are recorded in the diagnostic log. Persistent failures still stop the run with an error; these recovery paths do not turn incomplete deployment into success. Retry counts and delays are grouped in Get-OfficeDeploymentDefinitions; the standalone user helper has its MSI retry settings in Get-OfficeUserCleanupDefinitions.
Identity cleanup and absent users
The core script clears Office 15/16 identity/licensing registry keys and Office licensing token folders in each locally available non-special Windows profile, loading unloaded user hives when needed. Unavailable profiles/containers stop deployment before removal. FSLogix/roaming profiles that are not registered locally are outside this script's coverage.
Credential Manager belongs to each user. A limited-privilege scheduled task clears Office-prefixed credentials and removes per-user classic Teams. Before reinstallation begins, it also removes the user's old Teams meeting add-in and OneDrive. It runs immediately where a user session is available; otherwise it runs at that user's next sign-in. No passwords are stored. These tasks are named Emberkom-OfficeCleanup-<deployment-id>-<SID>.
An HKLM uninstall entry does not always mean the Teams meeting add-in is installed per-machine. The main script checks its actual machine registration through the read-only Windows Installer API before attempting a SYSTEM uninstall. The user helper checks both HKCU and HKLM uninstall entries, then selects only add-in products registered for that user. Removal is verified against that user's MSI registration, so another user's or a leftover display entry cannot cause a false failure. MSI query errors stop cleanup; the script does not delete uninstall registry keys to bypass verification. See Microsoft's installation context enumeration API.
A file lock serializes user uninstallers with the transition to reinstallation. Once the protected reinstall-started marker is written, later user tasks preserve the Teams meeting add-in and OneDrive so they cannot uninstall the newly deployed apps. For absent users, OneDrive's per-machine installer handles migration; an existing per-user Teams meeting add-in can remain even when the Teams client is not reinstalled. Cleanup completion does not mean that every old per-user companion artifact was purged. Office credentials and classic Teams are still cleaned on the next sign-in.
Windows work/school registration, WAM/AAD BrokerPlugin, generic Windows credentials, and device enrollment are preserved. This intentionally does not remove every Microsoft sign-in token. Microsoft's activation reset guide distinguishes Office caches from shared WAM and workplace registration state.
A deployment is reported as InstalledWithUserCleanupPending if any user task has not completed. Failed tasks also remain pending and retry on later sign-ins. The helper writes Status=Complete under HKCU\Software\Emberkom\OfficeDeployment\<deployment-id> after success and then becomes a no-op. Tasks completed during deployment are removed automatically. Tasks that finish later remain registered; an administrator can confirm their marker/task result and unregister those exact tasks afterward. Do not delete their helper while any cleanup is pending.
Results and troubleshooting
| Caller exit code | Meaning |
|---|---|
0 |
ValidationPassed: validation only, no deployment performed. Installed: Office and companion installations verified; user cleanup completed for the enumerated profiles. |
1 |
Failure; inspect the error and logs. In deployment mode, removal may already have happened. |
2 |
Office and companion apps installed, but user cleanup is pending. Sign in as the listed users and inspect task results; do not repeatedly reinstall merely to check status. |
3010 |
Restart required by an installer. Read OfficeDeploymentStatus: RestartRequiredBeforeInstall means restart then rerun; Installed or InstalledWithUserCleanupPending means Office and companions completed and an installer requested restart. Pending user SIDs can also be present. |
Syncro may flag nonzero results as errors; read the printed status and pending SIDs. Get Help recommends a restart after a successful scrub even when the installer does not return 3010. Schedule that restart separately.
If machine companion removal still fails verification, the error identifies the remaining component, version, and registry location, along with the uninstall log folder. The main log also records which add-in registrations were left to user cleanup. An uninstall exit code of 1605 alone does not establish that all users' installations are gone; Windows Installer context determines which stage handles the add-in. This failure occurs before Office scrub, identity reset, and reinstallation, but companion apps may already have been removed.
The main script uses the overridden Write-Output and Write-Error from Tools.ps1 for actions, retries, failures, and the final receipt, writing to its existing $Global:LogFile. Internal action messages suppress the logger's echoed success output to keep function results separate from diagnostics. The mode notice, log location, and final receipt use Microsoft.PowerShell.Utility\Write-Output for Syncro. Errors are logged and also printed to Syncro. Native PowerShell relaunch reloads Tools and restores the caller's log path. Run the core through the shim/Tools execution context, not as an independent file without Tools.
Process stdout/stderr logs, options, generated XML, and downloaded media remain in %ProgramData%\EmberkomOfficeDeployment\<deployment-id>. The main script records this folder in the Tools log and receipt. The separate limited-user cleanup task does not share the elevated Tools execution context; its transcript remains in %LOCALAPPDATA%\Emberkom\OfficeDeployment\<deployment-id>.log for each user. Retained media can consume several GB per attempt. A validation-only folder can be removed after reviewing its results; for deployment folders, first remove all associated scheduled tasks. ODT/Get Help may also write diagnostic logs to the executing account's temp directory.
The installer verifies the selected Office product, bitness, and downloaded version in Click-to-Run registration, plus selected companion deployment as listed above. The final receipt includes CompanionApps versions and TeamsSelected; when Teams is skipped, it has no installed version in that receipt. Any selected companion installer or verification failure fails the deployment, even if Office installed successfully. It does not claim that the subscription has activated. It does not delete mail profiles, revoke cloud sessions, or roll back a removed Office installation.
Verification
Run powershell.exe -NoProfile -ExecutionPolicy Bypass -File .\tests\Install-MicrosoftOffice365.Tests.ps1 for offline checks. They require Windows PowerShell 5.1 and exercise the default validation gate (including Force), explicit deployment opt-out, log/console routing with the real Tools helpers, XML, removal-result handling, bounded cache deletion, companion installer failures/verification, deferred cleanup protection, and the unchanged Run-Script receiving injected strings through the shim with a mocked workload. Recovery checks simulate busy MSI, delayed registration, transient downloads, Appx removal races, persistent failures, and completed-task housekeeping errors. Get Help regression cases use captured usage text, both result formats, zero-exit argument errors, and background workers/registration delays/timeouts. An inert executable checks actual native argument passing; a 32-bit Windows PowerShell child checks relaunch into 64-bit Windows PowerShell 5.1 and exit-code propagation. They do not run Microsoft installers or clear actual credentials.
Run-Script is unchanged. Its existing local execution can read the Syncro variables from the enclosing caller scope. The Office workload validates those values and reports its own result and exit code. The shim only sets TLS, dot-sources Tools.ps1, and invokes the workload. Existing Run-Script bootstrap failure behavior also remains unchanged.
Endpoint acceptance still requires a VM pilot: existing MSI/C2R/Store Office, machine/per-user Teams and OneDrive, a logged-off profile, standard-user sign-in, wrong-license rejection, download failure, and the restart path. Verify new Outlook and Teams registration at sign-in, OneDrive migration, and that delayed cleanup preserves reinstalled apps. The implementation has not been run destructively against a real endpoint during development.
Maintaining deployment definitions
Get-OfficeDeploymentDefinitions at the top of the main script groups subscription/product mappings, Teams and shared activation eligibility, allowed dropdown choices, download URLs/discovery patterns, installer arguments and package identities, language/build checks, OS minimums, cleanup targets, and timeouts. There is no additional configuration file. Review these contracts when Microsoft changes licensing, packaging, platform support, or cleanup behavior; evergreen downloads avoid routine version-number updates. Keep the Syncro dropdown definitions and this guide aligned when changing allowed selections. The limited-user helper retains its own scoped cleanup logic and version marker; changes to that contract require publishing both scripts together.