Update public Windows patch agent bootstrap

This commit is contained in:
2026-10-06 13:19:15 +00:00
parent f6fcc26a06
commit ab9f8b7c63
3 changed files with 53 additions and 4 deletions
+22
View File
@@ -141,6 +141,28 @@ What it does:
- normalizes any generated raw-IP PatchMon URLs back to the FQDN
- runs the PatchMon Windows installer
## Wheelz Windows patch status agent
Install the custom Windows patch status collector for PSU/Inventory. Run PowerShell as Administrator. The script prompts for the Windows patch enrollment token and posts status to `https://psu.local.wheelz.com/api/wheelz/patch/windows/status`.
```powershell
$u = "https://gitea.wheelytho.com/Wheelz/Docker-Install/raw/branch/main/WindowsPatchScripts/Install-WindowsPatchAgent.ps1"; $s = "$env:TEMP\Install-WindowsPatchAgent.ps1"; Invoke-WebRequest -Uri $u -OutFile $s -UseBasicParsing; powershell.exe -NoProfile -ExecutionPolicy Bypass -File $s
```
Non-interactive form:
```powershell
$u = "https://gitea.wheelytho.com/Wheelz/Docker-Install/raw/branch/main/WindowsPatchScripts/Install-WindowsPatchAgent.ps1"; $s = "$env:TEMP\Install-WindowsPatchAgent.ps1"; Invoke-WebRequest -Uri $u -OutFile $s -UseBasicParsing; powershell.exe -NoProfile -ExecutionPolicy Bypass -File $s -EnrollmentToken "<token>"
```
Local-only collector mode with no PSU posting:
```powershell
powershell.exe -NoProfile -ExecutionPolicy Bypass -File $s -LocalOnly
```
The collector installs to `C:\ProgramData\WheelzPatch`, creates scheduled task `Wheelz Windows Patch Status`, and writes local status to `C:\ProgramData\WheelzPatch\status.json`.
## Options
```text
@@ -15,6 +15,18 @@ if (-not (Test-Path $modulePath)) {
}
Import-Module $modulePath -Force
$configPath = Join-Path $repoRoot 'config.json'
if (Test-Path $configPath) {
try {
$config = Get-Content -Path $configPath -Raw | ConvertFrom-Json
if (-not $InventoryApiUrl -and $config.inventoryApiUrl) { $InventoryApiUrl = $config.inventoryApiUrl }
if (-not $InventoryApiToken -and $config.inventoryApiToken) { $InventoryApiToken = $config.inventoryApiToken }
}
catch {
Write-Warning "Failed to read WheelzPatch config.json: $($_.Exception.Message)"
}
}
$status = Get-WpmWindowsUpdateStatus -IncludeDrivers:$IncludeDrivers -IncludeInstalledHistory:$IncludeInstalledHistory
$inventoryPatch = [pscustomobject]@{
@@ -2,11 +2,13 @@
param(
[string]$RepositoryRawBase = 'https://gitea.wheelytho.com/Wheelz/Docker-Install/raw/branch/main',
[string]$InstallRoot = "$env:ProgramData\WheelzPatch",
[string]$InventoryApiUrl,
[string]$InventoryApiUrl = 'https://psu.local.wheelz.com/api/wheelz/patch/windows/status',
[string]$EnrollmentToken,
[string]$InventoryApiToken,
[string]$StatusSchedule = 'Every 4 hours',
[string]$PatchSchedule = 'Wednesday after Patch Tuesday · 2:00 AM CT',
[switch]$EnablePatchTask,
[switch]$LocalOnly,
[switch]$Force
)
@@ -15,6 +17,19 @@ if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdenti
throw 'Run this installer from an elevated PowerShell session.'
}
if ($LocalOnly) {
$InventoryApiUrl = $null
$InventoryApiToken = $null
}
elseif ($InventoryApiUrl) {
if (-not $EnrollmentToken -and -not $InventoryApiToken) {
$EnrollmentToken = Read-Host 'Enter Windows patch enrollment token'
}
if (-not $InventoryApiToken) { $InventoryApiToken = $EnrollmentToken }
if (-not $EnrollmentToken) { $EnrollmentToken = $InventoryApiToken }
if (-not $InventoryApiToken) { throw 'Enrollment token is required unless -LocalOnly is used.' }
}
$moduleDir = Join-Path $InstallRoot 'Modules\WindowsPatchManagement'
$scriptsDir = Join-Path $InstallRoot 'WindowsPatchScripts'
New-Item -Path $moduleDir,$scriptsDir -ItemType Directory -Force | Out-Null
@@ -32,7 +47,7 @@ foreach ($item in $downloads) {
$config = [ordered]@{
inventoryApiUrl = $InventoryApiUrl
inventoryApiToken = $InventoryApiToken
inventoryApiToken = $EnrollmentToken
patchWindow = $PatchSchedule
rebootPolicyEnabled = $false
installedAtUtc = (Get-Date).ToUniversalTime().ToString('o')
@@ -42,7 +57,7 @@ $config | ConvertTo-Json -Depth 8 | Set-Content -Path $configPath -Encoding UTF8
$statusArgs = @('-NoProfile','-ExecutionPolicy','Bypass','-File',"$scriptsDir\Get-WindowsPatchStatus.ps1")
if ($InventoryApiUrl) { $statusArgs += @('-InventoryApiUrl',$InventoryApiUrl) }
if ($InventoryApiToken) { $statusArgs += @('-InventoryApiToken',$InventoryApiToken) }
if ($InventoryApiToken) { $statusArgs += @('-InventoryApiToken',$EnrollmentToken) }
$statusArgument = (($statusArgs | ForEach-Object { if ($_ -match '\s') { '"{0}"' -f $_ } else { $_ } }) -join ' ')
$statusAction = New-ScheduledTaskAction -Execute 'powershell.exe' -Argument $statusArgument
$statusTrigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(5) -RepetitionInterval (New-TimeSpan -Hours 4) -RepetitionDuration (New-TimeSpan -Days 3650)
@@ -59,7 +74,7 @@ if ($EnablePatchTask) {
Register-ScheduledTask -TaskName 'Wheelz Windows Patch Install' -Action $patchAction -Trigger $patchTrigger -Principal $statusPrincipal -Force | Out-Null
}
& "$scriptsDir\Get-WindowsPatchStatus.ps1" -InventoryApiUrl $InventoryApiUrl -InventoryApiToken $InventoryApiToken | Out-Host
& "$scriptsDir\Get-WindowsPatchStatus.ps1" -InventoryApiUrl $InventoryApiUrl -InventoryApiToken $EnrollmentToken | Out-Host
Write-Host "Wheelz Windows Patch agent installed at $InstallRoot"
Write-Host 'Status task: Wheelz Windows Patch Status'
if ($EnablePatchTask) { Write-Host 'Patch task: Wheelz Windows Patch Install' } else { Write-Host 'Patch task not enabled yet; rerun with -EnablePatchTask after status reporting is trusted.' }