Private/Show-UpdateNotification.ps1
|
function Show-UpdateNotification { <# .SYNOPSIS Displays the update notification message. .DESCRIPTION Shows a formatted notification when a newer version of IROD is available on PowerShell Gallery. #> [CmdletBinding()] param( [Parameter(Mandatory)] [version]$CurrentVersion, [Parameter(Mandatory)] [version]$LatestVersion ) Write-Host "" Write-Host "[!] IROD update available: $CurrentVersion -> $LatestVersion" -ForegroundColor Red Write-Host "" $response = Read-Host "Update now? (Y/N) [Press Enter to skip]" if ($response -eq 'Y' -or $response -eq 'y') { Write-Host "" Write-Host "Updating IROD..." -ForegroundColor Cyan try { # Try Update-PSResource first (newer method) if (Get-Command Update-PSResource -ErrorAction SilentlyContinue) { Update-PSResource -Name IROD -Confirm:$false } # Fallback to Update-Module elseif (Get-Command Update-Module -ErrorAction SilentlyContinue) { Update-Module -Name IROD -Force } else { Write-Host "Update commands not found. Please run manually:" -ForegroundColor Yellow Write-Host " Update-Module -Name IROD" -ForegroundColor Yellow Write-Host "" Write-Host "Press Enter to continue" $null = [Console]::ReadLine() return } Write-Host "" Write-Host "Update complete! Please restart PowerShell and reimport the module." -ForegroundColor Green Write-Host "" Write-Host "Press Enter to Exit" $null = [Console]::ReadLine() exit } catch { Write-Host "" Write-Host "Update failed: $_" -ForegroundColor Red Write-Host "Please update manually with: Update-Module -Name IROD" -ForegroundColor Yellow Write-Host "" Write-Host "Press Enter to continue anyway" $null = [Console]::ReadLine() } } elseif ($response -eq 'N' -or $response -eq 'n') { Write-Host "Skipping update." -ForegroundColor Yellow Write-Host "" } else { Write-Host "" } } |