Fix WSB collector against a real server's object model

Checked with Get-WsbCollectorDiagnostics.ps1 output from a Server 2019
Hyper-V host (AAOG-EDM-HVR1):

- WBJob StartTime/EndTime are culture-formatted local-time strings
  ("10/6/2026 9:00 PM"). Parse them with the current culture: the
  [datetime] cast uses the invariant (US) format and would misread
  dd/MM dates, e.g. on en-CA/en-GB servers. Confirmed local, not UTC,
  against the Microsoft-Windows-Backup event log
- Hyper-V backups nest VMs under a VirtualMachineList item's
  SubItemList; failures, names and the items list now come from the
  leaf items, falling back to a parent's SubItemFailed count
- Report size from the top-level items' BytesProcessed
- FailureLogPath is set even on success: running backups get no
  message, and the log is only cited for warnings/failures
- HRESULTs are strings; conversion tolerates hex and bad values
- Mock rebuilt on the real shapes; tested under en-US and en-GB

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
2026-10-07 16:14:03 -06:00
co-authored by Claude Opus 5.5
parent a14b1b0dc9
commit b625a8af65
3 changed files with 125 additions and 44 deletions
+8 -8
View File
@@ -4,11 +4,10 @@ A PowerShell script that runs on each server using Windows Server Backup (WSB) a
backups to the dashboard. Each server appears as one job, named `<SERVER> - Windows Server Backup`
by default.
> **Not yet checked against a real server.** The cmdlets are the `WindowsServerBackup` module's own
> (`Get-WBJob`, `Get-WBSummary`), but the properties of the objects they return, and whether job
> times are local or UTC, aren't fully documented. Before installing on the first server, run
> `Get-WsbCollectorDiagnostics.ps1` and the collector with `-DryRun` (see below) to confirm what it
> reads.
> **Checked against:** Server 2019 Hyper-V host backing up VMs, successful backups only.
> Not yet seen on a real server: a failed backup, a failed VM or volume, or a backup in progress.
> Those paths are written to the same object model, but if one looks wrong, run
> `Get-WsbCollectorDiagnostics.ps1` while it's in that state and send the output.
## Install (on the server, as an administrator)
@@ -44,11 +43,12 @@ Re-run the installer to change settings or update the script.
|---|---|
| Company | `Tenant` from the config |
| Job | One per server, ID `wsb:<computer name>`, so changing `JobName` renames rather than duplicates it |
| Run | One per backup job from `Get-WBJob`, identified by its start time (WSB jobs have no ID). Restores are ignored |
| Run | One per backup job from `Get-WBJob`, identified by its start time (WSB jobs have no ID). Restores are ignored. `details.items` lists what was backed up: the VMs for a Hyper-V backup, otherwise volumes |
| Status | Error HRESULT → **Failed**. Success, but a detailed error or a failed item (e.g. one volume) → **Warning**. Cancelled or unrecognised → **Warning**. In progress → **Running** |
| Started / finished | Job start / end time |
| Started / finished | Job start / end time. WSB gives these as local-time text to the minute, in the server's date format; the collector parses them with that format |
| Next scheduled | `Get-WBSummary`'s `NextBackupTime`. Empty when there's no scheduled backup |
| Message | Error description, error codes (as `0x8XXXXXXX`), failed items, and the failure log path |
| Message | Error description, error codes (as `0x8XXXXXXX`), failed VMs/volumes, and the failure log path |
| Size | Bytes processed across the backup's items |
Each run covers the last 48 hours (`LookbackHours`). Runs already delivered are recorded in
`wsb-collector.state.json`.