From 28641c47c5af83021bd6b5fefe7b6dcc22a4251b Mon Sep 17 00:00:00 2001 From: cproudlock Date: Fri, 12 Dec 2025 09:45:42 -0500 Subject: [PATCH] v1.5.1: Startup warning if PC not registered in ShopDB MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Check API response on startup for "Unknown hostname" error - Display warning if PC not in ShopDB machines table - Skip API calls if PC not registered (avoid repeated failures) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 --- README.md | 1 + eDNC-SpecialCharFix.ps1 | 35 +++++++++++++++++++++++++++++++---- version.ini | 2 +- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index dd929d3..44bc508 100644 --- a/README.md +++ b/README.md @@ -130,6 +130,7 @@ The script uses exponential backoff (500ms → 1s → 2s → 4s → up to 16s) f | Version | Date | Changes | |---------|------|---------| +| 1.5.1 | 2025-12-12 | Startup warning if PC not registered in ShopDB | | 1.5.0 | 2025-12-12 | API logging to ShopDB (started, cleaned, failed, stopped events) | | 1.4.0 | 2025-12-12 | Auto-update from S:\DT\cameron\eDNC-Fix\version.ini every 5 min | | 1.3.1 | 2025-12-12 | Added Install-ScheduledTask.ps1 for running as SYSTEM service | diff --git a/eDNC-SpecialCharFix.ps1 b/eDNC-SpecialCharFix.ps1 index ce90ff5..0a50b92 100644 --- a/eDNC-SpecialCharFix.ps1 +++ b/eDNC-SpecialCharFix.ps1 @@ -36,9 +36,10 @@ .NOTES Author: GE Aerospace - Rutland - Version: 1.5.0 + Version: 1.5.1 Date: 2025-12-12 + v1.5.1 - Startup warning if PC not registered in ShopDB v1.5.0 - API logging: - Logs events (started, cleaned, ok, failed, error, stopped) to ShopDB API - Tracks installations and stats per hostname @@ -82,7 +83,7 @@ param( ) # Script info -$ScriptVersion = "1.5.0" +$ScriptVersion = "1.5.1" $ScriptName = "eDNC Special Character Fix" # Auto-update settings @@ -222,6 +223,9 @@ function Send-DNCEvent { [string]$Message = "" ) + # Skip if API is disabled (PC not registered or API unreachable) + if (-not $script:ApiEnabled) { return } + try { $body = @{ action = "logDNCEvent" @@ -260,8 +264,31 @@ Show-Header -Status "Watching for files... (Ctrl+C to stop)" | Out-Null Write-Host "Removing bytes: $($CharactersToRemove -join ', ') (0x$($CharactersToRemove | ForEach-Object { '{0:X2}' -f $_ } | Join-String -Separator ', 0x'))" -ForegroundColor DarkGray Write-Host "" -# Log startup to API -Send-DNCEvent -EventType "started" -Message "Script started" +# Log startup to API and check if PC is registered +$script:ApiEnabled = $true +try { + $body = @{ + action = "logDNCEvent" + hostname = $script:Hostname + eventType = "started" + version = $ScriptVersion + message = "Script started" + } + $response = Invoke-WebRequest -Uri $ApiUrl -Method POST -Body $body -ContentType "application/x-www-form-urlencoded" -UseBasicParsing -TimeoutSec 5 + $json = $response.Content | ConvertFrom-Json + if ($json.success -eq $false -and $json.error -match "Unknown hostname") { + $script:ApiEnabled = $false + Write-Host "WARNING: This PC ($($script:Hostname)) is not registered in ShopDB." -ForegroundColor Yellow + Write-Host " Activity will NOT be logged. Add this PC to ShopDB to enable logging." -ForegroundColor Yellow + Write-Host "" + } +} +catch { + # API unreachable - continue without logging + $script:ApiEnabled = $false + Write-Host "WARNING: Cannot reach ShopDB API. Activity will NOT be logged." -ForegroundColor Yellow + Write-Host "" +} # Statistics $script:FilesProcessed = 0 diff --git a/version.ini b/version.ini index fef5dc5..f2ddb68 100644 --- a/version.ini +++ b/version.ini @@ -1,2 +1,2 @@ [eDNC-Fix] -Version=1.5.0 +Version=1.5.1