Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $uninstallPaths = @(
- "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
- "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
- )
- Write-Host "=== Checking Veeam version consistency ==="
- $veeamProducts = @(
- @{
- Name = "VBR"
- RegistryPath = "HKLM:\SOFTWARE\Veeam\Veeam Backup and Replication"
- PathValueName = "CorePath"
- ExeName = "Veeam.Backup.Manager.exe"
- DisplayName = "Veeam Backup & Replication Server"
- },
- @{
- Name = "EM"
- RegistryPath = "HKLM:\SOFTWARE\Veeam\Veeam Backup Reporting"
- PathValueName = "ServicePath"
- ExeName = "Veeam.Backup.EnterpriseService.exe"
- DisplayName = "Veeam Backup Enterprise Manager"
- }
- )
- function Get-VeeamUninstallKey {
- param (
- [Parameter(Mandatory = $true)]
- [string]$DisplayName
- )
- foreach ($path in $uninstallPaths) {
- $key = Get-ChildItem $path -ErrorAction SilentlyContinue | ForEach-Object {
- $props = Get-ItemProperty $_.PsPath -ErrorAction SilentlyContinue
- if ($props.DisplayName -eq $DisplayName) { $_.PsPath }
- } | Select-Object -First 1
- if ($key) {
- return $key
- }
- }
- return $null
- }
- function Convert-ToVersionObject {
- param (
- [string]$VersionString
- )
- if (-not $VersionString) {
- return $null
- }
- try {
- return [version]($VersionString -replace '[^\d\.]', '')
- }
- catch {
- return $null
- }
- }
- $processedCount = 0
- foreach ($product in $veeamProducts) {
- Write-Host ""
- Write-Host "=== Processing $($product.DisplayName) ==="
- $installPath = (Get-ItemProperty -Path $product.RegistryPath -Name $product.PathValueName -ErrorAction SilentlyContinue).$($product.PathValueName)
- if (-not $installPath) {
- Write-Host "$($product.Name) not found in registry path $($product.RegistryPath). Skipping." -ForegroundColor Cyan
- continue
- }
- $exePath = Join-Path $installPath $product.ExeName
- if (-not (Test-Path $exePath)) {
- Write-Warning "$($product.ExeName) not found at: $exePath"
- continue
- }
- $newVersion = (Get-Item $exePath).VersionInfo.ProductVersion
- if (-not $newVersion) {
- Write-Warning "Could not determine file version from: $exePath"
- continue
- }
- Write-Host "Detected version from file: $newVersion"
- $veeamUninstallKey = Get-VeeamUninstallKey -DisplayName $product.DisplayName
- if (-not $veeamUninstallKey) {
- Write-Warning "Could not find Uninstall entry for '$($product.DisplayName)'."
- continue
- }
- $currentRegVersion = (Get-ItemProperty -Path $veeamUninstallKey -ErrorAction SilentlyContinue).DisplayVersion
- Write-Host "Registry currently lists version: $currentRegVersion"
- $currentVersionObject = Convert-ToVersionObject -VersionString $currentRegVersion
- $newVersionObject = Convert-ToVersionObject -VersionString $newVersion
- if (-not $currentRegVersion) {
- Write-Host "Registry version is empty. Updating registry..." -ForegroundColor Yellow
- Set-ItemProperty -Path $veeamUninstallKey -Name DisplayVersion -Value $newVersion
- Write-Host "Registry updated successfully at:`n $veeamUninstallKey" -ForegroundColor Green
- $processedCount++
- continue
- }
- if ($currentRegVersion -eq $newVersion) {
- Write-Host "Versions match. No update needed." -ForegroundColor Cyan
- $processedCount++
- continue
- }
- if ($currentVersionObject -and $newVersionObject) {
- if ($newVersionObject -gt $currentVersionObject) {
- Write-Host "Newer version detected ($newVersion > $currentRegVersion). Updating registry..." -ForegroundColor Yellow
- Set-ItemProperty -Path $veeamUninstallKey -Name DisplayVersion -Value $newVersion
- Write-Host "Registry updated successfully at:`n $veeamUninstallKey" -ForegroundColor Green
- }
- else {
- Write-Host "Registry version ($currentRegVersion) is equal or newer. No update needed." -ForegroundColor Cyan
- }
- }
- else {
- Write-Host "Version format could not be compared numerically. Updating registry to file version." -ForegroundColor Yellow
- Set-ItemProperty -Path $veeamUninstallKey -Name DisplayVersion -Value $newVersion
- Write-Host "Registry updated successfully at:`n $veeamUninstallKey" -ForegroundColor Green
- }
- $processedCount++
- }
- if ($processedCount -eq 0) {
- Write-Warning "No supported Veeam installations were processed."
- }
- Write-Host "`n=== Completed ==="
Advertisement
Add Comment
Please, Sign In to add comment