# Task-Sequence Series, User Prompts, and Cross-Site Replication

This document explains the **5-TS lifecycle**, the **prompt UI** that appears
at the right stage of each, and how to **replicate** the whole package across
multiple SCCM sites.

---

## 1. The 5 Task Sequences

| # | Task Sequence | When you use it | Wipes disk? | Keeps user data? | Typical caller |
|---|---|---|---|---|---|
| **TS-01** | `TS-01-RefImage-Build-And-Capture` | Once per quarter, in a lab VM, to produce a fresh patched, debloated reference WIM. | Yes (lab VM) | n/a | Build engineer |
| **TS-02** | `TS-02-BareMetal-Deploy` | Brand-new HP, returned-from-stock device, or any unit you want fully wiped. | **Yes** | No | Deployment tech |
| **TS-03** | `TS-03-InPlace-Upgrade` | Fleet-wide upgrade from Win10 / older Win11 to **Win11 24H2**, no re-image. | No | **Yes** | Patch operator |
| **TS-04** | `TS-04-Wipe-And-Load-USMT` | Same machine, but you want a fresh OS while keeping the user's profile/data. | Yes | **Yes** (USMT) | Field engineer |
| **TS-05** | `TS-05-Replace-USMT` | Hardware swap: capture from old PC, deploy new PC, restore user's state. | Yes (new PC) | **Yes** (USMT) | Hardware refresh tech |

All five are built by **`scripts/New-AllTaskSequences.ps1`** in a single
run. They share the same OS Image, Driver Packages, ConfigMgr Client
Package, OSD-Scripts package, HPIA package, and DP Group — so distribution
is done once.

### Recommended SCCM Collections

| Collection | Deployed TSes | Purpose |
|---|---|---|
| `OSD - Lab VMs` (Direct membership) | TS-01 | One Hyper-V VM in the build lab. |
| `OSD - Pilot HP Devices` (Direct) | TS-02 | Bench-test 1-3 units before broad release. |
| `OSD - Unknown Computers` (built-in) | TS-02 | All bare-metal HPs that PXE in. |
| `OSD - Refresh Candidates` (Query: AD OU) | TS-04 | Existing HPs slated for clean reimage with state. |
| `OSD - Win11 Upgrade Wave 1/2/3` (Query) | TS-03 | Phased fleet upgrade. |
| `OSD - Replacement Eligible` (Query) | TS-05 | Hardware refresh queue. |

---

## 2. User prompts at the right stage

Every TS except TS-01 and TS-03 launches **`OSDPrompt.hta`** as the first
visible step. The HTA is a small WinPE form that asks:

```
+-------------------------------------------------+
| Win11 HP Baseline Imaging                       |
| Build type: BareMetal                           |
|                                                 |
| Computer Name [P01-ABC1234567______________]    |
|                                                 |
| Department  [Engineering        v]              |
| App Bundle  [Standard           v]              |
|                                                 |
| Asset Tag   [_____________]                     |
| Technician  [____]                              |
|                                                 |
|                       [ Cancel ] [ Start » ]    |
+-------------------------------------------------+
```

What it writes into the TS environment (consumable by every later step):

| TS Variable | Type | Set by | Used downstream by |
|---|---|---|---|
| `OSDComputerName` | string (1-15) | HTA | *Apply Windows Settings* (built-in) |
| `OSDDepartment` | string | HTA | Application Group filter (Standard vs. Engineering bundle) |
| `OSDAssetTag` | string | HTA | `Set-Win11Baseline.ps1` writes to registry / asset DB |
| `OSDAppBundle` | enum | HTA | App-install step uses different App Group per value |
| `OSDBuildType` | enum | HTA arg | Audit + branching |
| `OSDTechnician` | string | HTA | Audit only |
| `OSDCancelled` | "true" | HTA | TS condition step exits cleanly |

### Why an HTA, not the built-in *Edit Task Sequence Variables* prompt?
Because the built-in prompt only handles a single computer-name field. The
HTA gives you department/role/asset tag/dropdowns and saves time for the
tech (defaulted name from BIOS serial, validation, branding).

### Stage timing of prompts in each TS
| TS | Prompt timing | What it asks | Why |
|---|---|---|---|
| TS-01 | none | n/a | Lab build, no per-machine input. |
| TS-02 | first step | full HTA | New machine, all metadata required. |
| TS-03 | early in OS phase | full HTA (some fields prefilled from existing PC) | In-place upgrade; tech still confirms identity + bundle. |
| TS-04 | first step | full HTA | Wipe-and-load — ideal time to update asset tag. |
| TS-05 (Old PC) | first step | abbreviated (Technician, optional comment) | State capture only. |
| TS-05 (New PC) | first step | full HTA | Treats new PC like bare-metal. |

### How to wire OSDPrompt.hta into the boot image
The HTA must live somewhere accessible from WinPE:

1. Create an SCCM **Standard Package** named `OSD-Prompt-HTA` whose source
   is `<SourceShare>\Apps\OSDPromptHTA\` (drop `OSDPrompt.hta` there).
2. Distribute it to your DP Group.
3. In `New-AllTaskSequences.ps1`, pass that PackageID via `-PromptHtaPackageId`.
4. Each TS gets a step **`0a. Collect User Input (HTA)`** that runs:
   ```
   cmd /c start /wait mshta.exe "%_SMSTSPackagesPath%\<HTAPackageID>\OSDPrompt.hta" /BuildType:BareMetal
   ```
5. Write a **TS condition** on every subsequent step:
   ```
   Variable OSDCancelled not equals "true"
   ```
   so a tech who clicks Cancel terminates cleanly without partial damage.

---

## 3. Cross-site replication

Use **`scripts/Replicate-TaskSequences.ps1`** to copy the entire series
(TSes + supporting source content) from a primary build site to one or more
peer sites.

### Strategy

```
[ SOURCE primary site - master copy ]
         │
         │  Export-CMTaskSequence (.zip per TS)
         │  Robocopy /MIR of OSD source share
         ▼
[ TRANSIT folder C:\OSDReplication\ ]
         │
         │  for each target:
         │    1. Robocopy share to target's UNC root
         │    2. Import-CMTaskSequence (.zip) on target site
         │    3. Distribute to target's DP Group
         ▼
[ TARGET site A ]   [ TARGET site B ]   [ TARGET site C ]
```

### Example — lab → east + west primaries

```powershell
$targets = @(
    @{ SiteCode = 'S01'
       SiteServer = 'sccm-east.contoso.local'
       Share      = '\\sccm-east\Sources$\OSD'
       DPGroup    = 'East DPs' },
    @{ SiteCode = 'S02'
       SiteServer = 'sccm-west.contoso.local'
       Share      = '\\sccm-west\Sources$\OSD'
       DPGroup    = 'West DPs' }
)

.\Replicate-TaskSequences.ps1 `
    -SourceSiteCode    P01 `
    -SourceSiteServer  sccm01.contoso.local `
    -SourceShare       '\\sccm01\Sources$\OSD' `
    -Targets           $targets `
    -Verbose
```

### What the script does

1. **Export** each TS in the series via `Export-CMTaskSequence` to
   `C:\OSDReplication\TS-XX-….zip`. SCCM bundles step XML + dependency
   metadata, but **not** the binary content of referenced packages.
2. **Robocopy** `\\sccm01\Sources$\OSD` → each target's
   `\\sccm-east\Sources$\OSD` etc. with `/MIR /XO` (mirrors only changed
   files; safe to re-run).
3. **Switch site** to each target via `New-PSDrive -PSProvider CMSite`.
4. For each TS:
   - Rename the existing copy on the target to `<TSName>.bak.<timestamp>`
     (idempotent rollback path).
   - `Import-CMTaskSequence -ZipFilePath ... -ImportObjectChange Overwrite`
     resolves package references against the now-local PackageIDs.
   - `Start-CMContentDistribution -DistributionPointGroupName <target-DPG>`.
5. **Re-runnable** weekly / on-demand. Subsequent runs only push deltas.

### Caveats

| Caveat | Mitigation |
|---|---|
| Target site has **different** PackageIDs for OS Image, Client Pkg, etc. | Run `New-SCCMOsdPackages.ps1` on the target *first* (it writes a per-target `PackageIDs.json`). The TS importer auto-resolves by **name** when overwrite is set. |
| WinPE driver injection is per-site (every target has its own boot image). | Run `New-HPBootImage.ps1` against each target site once. |
| **Drift** — someone edits a TS on a target, you replicate, edits are lost. | Make the source the only writable copy; targets are deploy-only. The `.bak.<ts>` rename gives you a recovery path. |
| Bandwidth on replication day. | Schedule overnight; Robocopy `/MT:8` keeps it efficient. |

### "True" SCCM DRS
If you have a **CAS (Central Administration Site) + child primaries**
hierarchy, you can rely on SCCM's built-in *DRS — Data Replication Service*
to push global objects (TSes, applications, packages) automatically. In that
case use this script only to ensure source share content is consistent
(DRS does **not** replicate file content — only object metadata).

---

## 4. Lifecycle: end-to-end run order

```
            +----------------------+
            | 1. (Lab) build WIM   |  TS-01-RefImage-Build-And-Capture
            +----------+-----------+
                       │ Win11-24H2-Ref.wim
                       ▼
            +----------------------+
            | 2. New-SCCMOsd       |  Pre-create OS Image, packages
            |    Packages.ps1      |  PackageIDs.json
            +----------+-----------+
                       │
                       ▼
            +----------------------+
            | 3. New-AllTask       |  Builds TS-01..TS-05
            |    Sequences.ps1     |
            +----------+-----------+
                       │
                       ▼
            +----------------------+
            | 4. Replicate-TS .ps1 |  Optional: push to other sites
            +----------+-----------+
                       │
                       ▼
   +-------------------------+-------------------------+
   |             |           |           |             |
   ▼             ▼           ▼           ▼             ▼
 New HP     Refresh PC   Win10->11    Hardware     Lab WIM
 (TS-02)    (TS-04)      (TS-03)      swap (TS-05) refresh (TS-01)
```

---

## 5. Quick reference

| Need to… | Run this |
|---|---|
| Build all 5 TSes from scratch | `.\New-AllTaskSequences.ps1` |
| Push series to a peer SCCM site | `.\Replicate-TaskSequences.ps1` |
| Add a new HP model to the driver matrix | edit `Get-HPDriverPacks.ps1 -Models`, then re-run wizard |
| Change the prompt UI fields | edit `applications/OSDPrompt.hta`; re-distribute the HTA package |
| Add an extra App Bundle (e.g. CAD bundle) | publish a new SCCM Application Group, add an `OSDAppBundle = "CAD"` value to the HTA dropdown, edit TS-02/04/05 step 4 to branch on `OSDAppBundle` |
| Verify a target site got the latest copy | on target: `Get-CMTaskSequence -Fast \| Where Name -Like 'TS-0*-*' \| ft Name,LastRefreshTime` |
