fixed Install-MicrosoftOffice365.ps1
added Repair-OneDriveKnownFolderPaths.ps1
This commit is contained in:
@@ -83,6 +83,12 @@ These follow Microsoft's deployment guidance for [Teams](https://learn.microsoft
|
||||
|
||||
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.
|
||||
|
||||
Teams now uses a [unified app for work, school, and personal accounts](https://techcommunity.microsoft.com/blog/microsoftteamsblog/unified-teams-app-for-work-personal-and-education-accounts-is-now-available-on-a/4217988). `teamsbootstrapper.exe -p` is Microsoft's business deployment method; verification requires the Microsoft-published `MSTeams` package and logs its package identity. The old personal-only `MicrosoftTeams` package does not satisfy that check. Users should add/select their licensed work or school account; a personal account can show the Teams Free experience in the same unified app. The script does not choose a Teams account or change sign-in policy.
|
||||
|
||||
A window that offers **Get Microsoft Teams (work or school)** does not by itself identify the installed package. Check the running executable path: `WindowsApps\MSTeams_<version>\ms-teams.exe` identifies the current client; do not attribute that window to an older personal-client process. Microsoft [documents support for personal and work/school accounts in the downloaded app](https://support.microsoft.com/en-us/teams/platform/how-do-i-get-microsoft-teams). Test **Create or use another account** with the licensed work account and record any actual sign-in error before changing deployment or sign-in policy. Machine provisioning alone does not prove a user's work-account sign-in succeeds.
|
||||
|
||||
Shutdown detection includes `Teams.exe`, `msteams.exe` (older personal/Windows Chat), and `ms-teams.exe`: `Abort` reports these running apps, while an actual deployment with `Force` closes them before removal. Earlier script versions omitted `msteams.exe`; this omission can leave that older process running, but does not explain a window confirmed to be running from `MSTeams\ms-teams.exe`. A sign-out/sign-in or restart can finish session/app registration changes; it is not a guaranteed fix for an unexplained sign-in screen.
|
||||
|
||||
Removal starts with the separate targeted Appx/provisioned-package and Teams/OneDrive uninstall operations. ODT then runs `setup.exe /configure remove.xml` with `<Remove All="TRUE" />` and `<Display Level="None" AcceptEULA="TRUE" />` to remove Click-to-Run Office, Visio, and Project without installation UI. The XML honors `OfficeAppShutdown`; `Abort` does not silently become `Force`. The script waits for setup to exit and verifies that non-MSI Office registrations disappear, allowing up to five minutes for registration changes. It skips this separate pass when only MSI Office, or no Office, is detected. See the [ODT configuration reference](https://learn.microsoft.com/en-us/microsoft-365-apps/deploy/office-deployment-tool-configuration-options).
|
||||
|
||||
Legacy MSI Office is handled by `<RemoveMSI />` in `install.xml`: ODT removes those products before installing the replacement suite in the same operation. Microsoft's [RemoveMSI guidance](https://learn.microsoft.com/en-us/microsoft-365-apps/deploy/upgrade-from-msi-version) covers Office, Visio, and Project 2007/2010/2013/2016. The script does not assume that a standalone `RemoveMSI` configuration without an installation is supported. Consequently, MSI Office can still be present during our identity/user-cleanup phase. After ODT finishes installation, the script verifies that detected MSI Office registrations are gone and the requested new product/version is installed. A completed MSI migration reports `3010` because a restart is required to finish removal, even if ODT returns zero.
|
||||
@@ -98,6 +104,7 @@ Transient failures get bounded recovery before deployment stops:
|
||||
- After successful operations, machine removal and installation verification allow up to five minutes of polling for registry/package state to settle. The standalone user's Teams add-in verification retains its 60-second allowance. 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.
|
||||
- Failure to create/register a user's cleanup task is logged with its SID, profile path, and error, then scheduling continues for the remaining profiles and Office installation proceeds. This handles stale profiles whose accounts no longer resolve, without assuming that every unresolved account has been deleted. Registration failures remain visible in the receipt and are not described as tasks waiting for sign-in. Active cleanup and its transition lock must still finish before installation to prevent concurrent uninstall/install operations.
|
||||
|
||||
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`.
|
||||
|
||||
@@ -115,6 +122,8 @@ Windows work/school registration, WAM/AAD BrokerPlugin, generic Windows credenti
|
||||
|
||||
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 retain their previous behavior: they remain registered but do no further work after success. An administrator can confirm completion and remove those exact tasks and their helper afterward. There is no daily housekeeping task.
|
||||
|
||||
If any cleanup task could not be registered, successful installation instead returns **InstalledWithUserCleanupIncomplete** with `UserCleanupRegistrationFailures` entries containing `SID`, `ProfilePath`, and `Error`. `PendingUserSids` still lists only registered tasks awaiting completion. Signing in alone cannot retry a missing task: review whether the profile belongs to a deleted account or whether account lookup/task registration needs repair. The script does not delete profiles or grant a different account access to their credentials. The machine-side Office identity/cache cleanup still runs before task registration.
|
||||
|
||||
The helper, lock, and reinstall marker for these previously agreed logon tasks live separately in `%ProgramData%\EmberkomOfficeDeployment\<deployment-id>`, so routine temp cleanup cannot break deferred user cleanup. The receipt identifies this folder as `UserCleanupWorkspace`. If no user tasks remain at the end of a successful deployment, the script removes this helper folder too. It is the only deployment code intentionally retained for pending users; the main installer does not persist on the endpoint.
|
||||
|
||||
## Temporary media and cleanup during deployment
|
||||
@@ -134,10 +143,10 @@ Earlier ProgramData caches are not searched for reuse in the new temp location.
|
||||
| --- | --- |
|
||||
| `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` | A restart is required. Read `OfficeDeploymentStatus`: `RestartRequiredBeforeInstall` means restart then rerun; `Installed` or `InstalledWithUserCleanupPending` means Office and companions completed with a restart deferred until afterward. `RestartRequired=true` and `DeferReboot` are included; a stop before installation also identifies `RestartStage`. Pending user SIDs can also be present. |
|
||||
| `2` | Office and companion apps installed, but user cleanup is pending or incomplete. `InstalledWithUserCleanupPending`: sign in as the listed `PendingUserSids` and inspect task results. `InstalledWithUserCleanupIncomplete`: also review `UserCleanupRegistrationFailures`; those users do not have a registered cleanup task. Do not repeatedly reinstall merely to check status. |
|
||||
| `3010` | A restart is required. Read `OfficeDeploymentStatus`: `RestartRequiredBeforeInstall` means restart then rerun; any `Installed*` status means Office and companions completed with a restart deferred until afterward. `RestartRequired=true` and `DeferReboot` are included; a stop before installation also identifies `RestartStage`. Pending user SIDs and task registration failures can also be present. |
|
||||
|
||||
Syncro may flag nonzero results as errors; read the printed status and pending SIDs. Schedule any required restart separately. The script also returns `3010` after verified legacy MSI Office removal, following Microsoft's restart requirement.
|
||||
Syncro may flag nonzero results as errors; read the printed status, pending SIDs, and task registration failures. Schedule any required restart separately. The script also returns `3010` after verified legacy MSI Office removal, following Microsoft's restart requirement.
|
||||
|
||||
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 removal, identity reset, and reinstallation, but companion apps may already have been removed.
|
||||
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
# Prepare known-folder paths for OneDrive
|
||||
|
||||
`Repair-OneDriveKnownFolderPaths.ps1` scans Documents, Pictures, and Desktop and
|
||||
proposes shorter filenames where their names or full paths exceed a length
|
||||
budget. Preview is the default. Apply mode renames files **in place**; it does not
|
||||
move files, rename folders, configure OneDrive, or enable folder backup.
|
||||
|
||||
## Preview, review, apply
|
||||
|
||||
Run in Windows PowerShell 5.1 or PowerShell 7 on Windows. For another user, run
|
||||
with access to that user's files and registry hive. Close applications using the
|
||||
affected files and pause OneDrive sync while applying renames. Renaming can break
|
||||
shortcuts, application references, and links that depend on the original name.
|
||||
|
||||
```powershell
|
||||
$options = @{
|
||||
UserProfilePath = 'C:\Users\Jane'
|
||||
OneDriveRoot = 'C:\Users\Jane\OneDrive - Contoso'
|
||||
Apply = $false
|
||||
ReportDirectory = 'C:\ProgramData\Emberkom\Output\OneDrivePathPreparation'
|
||||
}
|
||||
$preview = .\Repair-OneDriveKnownFolderPaths.ps1 -Options $options
|
||||
Import-Csv -LiteralPath $preview.ResultPath |
|
||||
Format-Table Status, OriginalPath, NewPath -Wrap
|
||||
|
||||
# After reviewing the proposed filenames and unresolved rows:
|
||||
$options.Apply = $true
|
||||
$result = .\Repair-OneDriveKnownFolderPaths.ps1 -Options $options
|
||||
```
|
||||
|
||||
`-WhatIf` also suppresses renames when `Apply` is true; diagnostic reports are
|
||||
still written. Each invocation rescans and creates a new plan, so an apply run
|
||||
can differ from an earlier preview if the files have changed.
|
||||
|
||||
When running as the affected user, `UserProfilePath` can be omitted. When only
|
||||
one OneDrive account is configured, `OneDriveRoot` can also be omitted. An
|
||||
ambiguous or missing account requires an explicit destination. SYSTEM and
|
||||
service accounts must identify a target profile; the script never guesses the
|
||||
logged-on user or scans every profile.
|
||||
|
||||
The target profile's loaded `User Shell Folders` registry key resolves redirected
|
||||
folders. Its own environment values resolve variables such as `%USERPROFILE%`
|
||||
and `%OneDriveCommercial%`. If its hive is not loaded, sign the user in or supply
|
||||
all source paths explicitly (no registry hive is loaded by this script):
|
||||
|
||||
```powershell
|
||||
$options.KnownFolderPaths = @{
|
||||
Documents = 'D:\UserData\Jane\Documents'
|
||||
Pictures = 'D:\UserData\Jane\Pictures'
|
||||
Desktop = 'D:\UserData\Jane\Desktop'
|
||||
}
|
||||
# OneDriveRoot must also be explicit to bypass registry discovery completely.
|
||||
```
|
||||
|
||||
Use actual known folder locations, especially when backup is already partially
|
||||
enabled. Paths must be absolute local drive paths. Overlapping source roots,
|
||||
network paths, and reports inside the scanned folders or destination are rejected.
|
||||
|
||||
## Length limits and rename behavior
|
||||
|
||||
[Microsoft documents](https://support.microsoft.com/en-us/onedrive/what-are-file-path-length-limits)
|
||||
a 400-character cloud path limit, 255-character individual names, and a
|
||||
520-character combined sync path with a root allowance of 120 characters.
|
||||
Windows applications can impose shorter limits.
|
||||
|
||||
The script defaults to **240 characters for both the current and projected local
|
||||
path**, leaving room below common Windows path limits. This is a conservative
|
||||
operational default, not OneDrive's cloud limit; it can propose renaming files
|
||||
that OneDrive itself would accept. `MaxPathLength` accepts 40–520, and
|
||||
`MaxNameLength` accepts 16–255 (default 255). The 400-character path relative to
|
||||
the OneDrive root is always enforced independently. These checks do not guarantee
|
||||
compatibility with every application's own limits.
|
||||
|
||||
For folders outside the chosen OneDrive root, the projection is
|
||||
`OneDriveRoot\Documents`, `OneDriveRoot\Pictures`, or `OneDriveRoot\Desktop`, plus
|
||||
the existing relative path. Folders already beneath that root retain their
|
||||
existing relative location. Review this assumption against the intended backup
|
||||
layout before applying changes.
|
||||
|
||||
Only over-budget filenames are shortened. The script retains a readable prefix,
|
||||
adds `~` and eight deterministic hash characters, and preserves the final
|
||||
extension. For example: `Long proposal title~1a2b3c4d.docx`. Further suffixes resolve
|
||||
collisions with existing files, directories, or other proposed names. It never
|
||||
overwrites a destination. A filename must have room for at least one prefix
|
||||
character, the suffix, and its extension. If it cannot fit, the file is reported
|
||||
as `NeedsFolderCleanup` without changing it. A leading-dot file whose entire
|
||||
name is treated as an extension may also require manual cleanup.
|
||||
|
||||
Folder names and nesting are never changed automatically. Long folder paths,
|
||||
including empty folders, are reported. Hidden/system entries are included.
|
||||
Unicode extended-path Windows APIs allow existing paths longer than 260
|
||||
characters to be enumerated and renamed without changing Windows policy.
|
||||
Junctions, symlinks, and unknown reparse points are skipped, including their
|
||||
subtrees. Modern Cloud Files placeholders are allowed; no file contents are read
|
||||
by the preparation script. An unavailable cloud provider or a locked file may
|
||||
still prevent enumeration or renaming and will be reported.
|
||||
|
||||
## Reports and failures
|
||||
|
||||
Each run writes a unique directory beneath `ReportDirectory` (default:
|
||||
`%TEMP%\OneDrivePathPreparation` for the executing account):
|
||||
|
||||
- `plan.csv`: original paths, proposed paths, projected OneDrive paths, lengths,
|
||||
and issues; written before any rename.
|
||||
- `results.csv`: the outcome for each proposed rename or issue. Files already
|
||||
within budget are omitted, but counted in the summary.
|
||||
- `journal.csv`: apply runs record `Pending` before each rename and its outcome
|
||||
afterward; each record is flushed to disk. Keep this with the plan/results.
|
||||
|
||||
Statuses include `Preview`, `Renamed`, `NeedsFolderCleanup`, `InvalidName`,
|
||||
`SkippedReparsePoint`, `ScanError`, `NotApplied`, and `RenameFailed`. Invalid-name
|
||||
rows flag common non-length restrictions without fixing them. `desktop.ini` and
|
||||
Office lock files may be expected exclusions; this is not a complete OneDrive
|
||||
readiness audit.
|
||||
|
||||
Any `ScanError` prevents **all** renames in that run. Other unresolved items are
|
||||
reported while fixable filenames can still be renamed. Individual rename
|
||||
failures are recorded and the run continues. Report/journal write failures stop
|
||||
the run. Existing successful renames are not rolled back automatically. After an
|
||||
interruption, a final `Pending` journal row means the rename outcome is uncertain;
|
||||
check both paths. Original names in the reports support manual restoration,
|
||||
provided the old path is unoccupied. Protect reports as they contain user paths.
|
||||
|
||||
The returned summary includes `FilesScanned`, `FoldersScanned`, `Previewed`,
|
||||
`Renamed`, `ReviewNeeded`, `ScanErrors`, and report paths. `ReviewNeeded` counts
|
||||
issue rows, not unique files. RMM runs print these counts and the results path;
|
||||
review them even when PowerShell exits normally. After resolving remaining
|
||||
issues, resume sync, enable/retry OneDrive folder backup, and verify its status.
|
||||
This script does not certify that cloud backup completed.
|
||||
|
||||
## RMM caller
|
||||
|
||||
Publish the main script, then upload/paste
|
||||
[the caller](../rmm/Repair-OneDriveKnownFolderPaths.ps1) into Syncro as a Windows
|
||||
PowerShell 5.1 script with **Run As: System**. As with the Microsoft 365 installer,
|
||||
configure individual script variables in the RMM; the caller does not assign or
|
||||
overwrite their values. Enter variable names without `$`.
|
||||
|
||||
| Variable | Value / recommended default |
|
||||
| --- | --- |
|
||||
| `UserProfilePath` | Target profile, e.g. `C:\Users\Jane`; required for the normal SYSTEM workflow |
|
||||
| `OneDriveRoot` | Intended destination, e.g. `C:\Users\Jane\OneDrive - Contoso` |
|
||||
| `Apply` | Dropdown: `false`, `true`; default **`false`** (preview) |
|
||||
| `MaxPathLength` | `240`; allowed range 40–520 |
|
||||
| `MaxNameLength` | `255`; allowed range 16–255 |
|
||||
| `ReportDirectory` | `C:\ProgramData\Emberkom\Output\OneDrivePathPreparation` |
|
||||
| `DocumentsPath` | Optional source override; default `Auto` |
|
||||
| `PicturesPath` | Optional source override; default `Auto` |
|
||||
| `DesktopPath` | Optional source override; default `Auto` |
|
||||
|
||||
All values are strings. Every variable configured in Syncro needs a nonempty
|
||||
value. The three source overrides can be omitted from the RMM entirely; if added,
|
||||
use `Auto` for all three to discover the user's folders, or provide all three
|
||||
absolute paths. Partial overrides fail before scanning. Explicit source paths
|
||||
plus `OneDriveRoot` permit scanning without a loaded user registry hive.
|
||||
|
||||
First run with `Apply=false`, inspect the CSV, then select `true` to apply renames.
|
||||
The caller only bootstraps Tools and runs:
|
||||
|
||||
```powershell
|
||||
Run-Script -LivePSScript Repair-OneDriveKnownFolderPaths
|
||||
```
|
||||
|
||||
The core reads the individual shared variables without changing them. Missing
|
||||
or blank values use the core defaults: preview, 240/255 length limits, and reports
|
||||
under the executing account's temp directory. Missing profile/OneDrive inputs
|
||||
follow the discovery and SYSTEM restrictions described above. The RMM's suggested
|
||||
report path above takes effect when supplied as `ReportDirectory`.
|
||||
|
||||
Standalone `-Options` still takes precedence. If it is absent and any of these
|
||||
individual variables exist, they form the complete configuration with defaults;
|
||||
the legacy `$OneDrivePrepOptions` hashtable is used only when no individual inputs
|
||||
exist. This prevents a stale legacy `Apply=true` from enabling changes when a new
|
||||
RMM caller omits `Apply`.
|
||||
|
||||
`Tools.ps1` is unchanged. Apply accepts Boolean values or RMM strings
|
||||
`true`, `$true`, `yes`, `y`, `1`; `false`, `$false`, `no`, `n`, `0`, blank, and null
|
||||
disable changes. Unknown values fail before scanning. Option-name typos also fail.
|
||||
|
||||
## Offline verification
|
||||
|
||||
```powershell
|
||||
powershell.exe -NoProfile -File .\tests\Repair-OneDriveKnownFolderPaths.Tests.ps1
|
||||
pwsh.exe -NoProfile -File .\tests\Repair-OneDriveKnownFolderPaths.Tests.ps1
|
||||
```
|
||||
|
||||
Tests use synthetic files in a unique scratch directory under the repository,
|
||||
then remove that directory. They cover preview/apply, real paths longer than 260
|
||||
characters, collisions, preserved contents/extensions, projected destination
|
||||
length, Unicode, deep-folder reporting, WhatIf, incomplete scans, repeat runs,
|
||||
the rename journal, and RMM shared-scope execution (individual string variables,
|
||||
defaults, precedence, and legacy callers) with downloads replaced by local fixtures.
|
||||
They do not contact OneDrive or verify cloud synchronization.
|
||||
Reference in New Issue
Block a user