Production PowerShell deployment script for remote MSI/MSIX installs with robust credential validation, batch orchestration, retry handling, reboot evaluation, and aggregated logging.
Owner: Andrew Lucas
Last Modified: March 2, 2026
PowerShell Version Required: 5.1+ (7+ recommended for parallel)
Install-RemoteMSI.ps1 performs silent remote installs in two modes:
- Single-machine mode
- Batch mode from
.txt/.csv
High-level flow:
- Runtime host bootstrap check (PS version, optional PS7 relaunch/install path)
- Credential validation against domain services (AD/DC) before heavy processing
- Operator account confirmation prompt (shows active account, optional credential override)
- Target sanitization and five-state batch pre-validation (AD/DNS/reachability/WinRM)
- Authorization canary check on up to 3 ready machines
- Installer selection from script directory
- Transfer with retry policy (
5s,10s,30s,60s) - Silent install (
msiexec /quiet /norestart) - Install result normalization (exit descriptions + final per-machine result)
- Failed-machine-only retry rounds
- Summary table + one aggregated run log
Reboot handling is now installation-only for result reporting:
- Script snapshots reboot indicators pre-install and post-install.
RebootRequiredis set toYesonly if the install itself triggered reboot requirement (MSI code1641/3010or newly introduced reboot indicators after install).- Pre-existing reboot state on the machine is not counted as install-required reboot in final result.
- Summary table shows reboot as a simple
Yes/Nocolumn.
Primary functions:
Get-PendingRebootStateGet-RebootRequirementEvaluation
| Function | Purpose |
|---|---|
Write-Log |
Colored console + timestamped run log output |
Test-InstallerFilesExist |
Verifies MSI/MSIX exists in script directory |
Get-InstallerFiles / Get-MSIFile |
Installer discovery + selection |
Get-ValidatedSingleHostname |
Single-target input + sanitization |
Find-BatchMachineFile |
Batch file discovery / selection |
Get-MachineNamesFromFile |
First-column parsing + sanitization |
Get-MachineAvailabilityReport |
Five-state machine validation + ready-target extraction |
Request-Credentials |
Terminal Read-Host credential prompt |
Get-ValidatedCredentialForDomain |
Early AD/DC credential validation |
Get-CredentialAfterUserConfirmation |
Always-on account prompt + optional credential override |
Invoke-AuthorizationCanaryCheck |
Preflight remote-admin authorization check (up to 3 machines) |
Copy-MSIWithRetry |
Retry transfer policy and operator retry/abort prompt |
Get-PendingRebootState |
Reads reboot indicators (registry + WMI) |
Get-RebootRequirementEvaluation |
Determines install-caused reboot required (Yes/No) |
Remove-RemoteMSI |
Removes installer from remote machine when applicable |
Invoke-MachineInstall |
Sequential single-machine execution path |
Invoke-Deployment |
Batch orchestration incl. parallel path + retry rounds |
Write-Summary |
Final run summary and result table |
Main |
End-to-end orchestration |
PHASE 0: Runtime bootstrap (PS host/version gate)
PHASE 1: Installer file verification/selection
PHASE 2: Mode selection (Single/Batch)
PHASE 3: Target input + sanitization
PHASE 4: Credential validation first (AD/DC)
PHASE 5: Operator account confirmation (optional credential override)
PHASE 6: Batch pre-validation by five machine-availability states
PHASE 7: Authorization canary check on up to 3 ready machines
PHASE 8: Session creation + remote temp prep
PHASE 9: Transfer with retry policy
PHASE 10: Silent install and exit code capture
PHASE 11: Install-caused reboot evaluation (pre/post snapshot compare)
PHASE 12: Cleanup, per-machine retries, summary, and logging
- Credential validation runs before heavy processing.
- Credential prompts are terminal-based (
Read-Host) only. - Hostname sanitization applies to single and batch modes.
- Batch file parsing uses first column; header not required.
- Batch pre-validation is done before deployment workers start and excludes non-ready states.
- Transfer retry delays are fixed:
5,10,30,60seconds. - Failed machine retries occur after each batch and only for failed targets.
- MSI retention policy: preserve on most failures; remove on success and corruption/open failure (
1619). - Successful machines are commented in source batch file for reruns.
- PS7 startup gate remains in place; fallback behavior preserved.
- Optional PS7 install via configured Windows Update service remains available in interactive runs.
- Reboot summary/reporting is installation-only
Yes/No(pre-existing reboot not counted). - Credential pre-check is domain-auth based (not probe-machine endpoint based).
- Batch mode fails fast if no machine is fully reachable after pre-validation.
- Operator is always shown active execution account and can choose alternate credentials before canary/deployment.
- Authorization canary validates remote-admin rights on up to 3 ready machines before deployment starts.
- Batch pre-validation emits in-place status updates (non-animated) and uses the operator-facing wording: "Executing machine-state validation for batch processing list."
- If pre-validation yields zero ready machines, script prints a machine-state summary table (all parsed machines + derived state) before terminating.
- Parallel execution requires PowerShell 7+; script falls back to sequential when unavailable.
- Console uses animated spinner progress for installer execution and in-place status updates for batch pre-validation.
- Quiet MSI execution does not provide reliable granular percentage progress.
- Aggregated run log is reused across PS5→PS7 relaunch path via
-RunLogPath. - Reachability-only machines with WinRM disabled are excluded before deployment.
- Authorization canary failure stops deployment before install execution begins.
- Zero-ready pre-validation now renders a summary table so operators can review derived state per machine even when no install jobs run.
- Password entry uses
Read-Host -AsSecureString. - Credentials are not logged or persisted to disk.
PSCredentialis used in-memory for remoting only.
Built-in cmdlets only (no mandatory external modules):
- Remoting:
New-PSSession,Invoke-Command,Remove-PSSession - Transfer:
Copy-Item - Validation:
Resolve-DnsName,Test-Connection - Reboot probes: registry lookups +
Get-WmiObject - Logging:
Add-Content
Remote machine prerequisites:
- WinRM enabled
- Admin-capable credentials
- Single mode success path (exit
0) works end-to-end - Batch mode with mixed success/failure behaves correctly
- Domain credential validation rejects invalid credentials within 2 attempts
- Account confirmation prompt always displays active execution identity
- Batch pre-validation correctly classifies all five machine states
- In-place pre-validation status updates appear after the operator-facing validation message
- If zero machines are ready after pre-validation, summary table still lists all machines with derived state
- Authorization canary checks up to 3 machines and blocks deployment on failure
- Transfer retry and retry-cycle prompt works
- Failed-machine-only retry prompt logic works
- Reboot column is
Yesonly for install-caused reboot requirement - Summary table includes
Rebootcolumn only (no reboot-reason column) - Successful machine comment-out mutation in batch source file works
- Console + log timestamps/severity are consistent
When modifying this script:
- Keep changes scoped and aligned with current decisions above.
- Preserve credential-first and retry behavior unless user explicitly requests change.
- Update both
README.mdandAI_BRIEFING.mdwhen behavior changes. - Validate script parse and diagnostics before handoff.
End of Briefing