Guest User

Untitled

a guest
Mar 23rd, 2026
37
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.69 KB | None | 0 0
  1.  
  2. $uninstallPaths = @(
  3. "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
  4. "HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"
  5. )
  6.  
  7. Write-Host "=== Checking Veeam version consistency ==="
  8.  
  9. $veeamProducts = @(
  10. @{
  11. Name = "VBR"
  12. RegistryPath = "HKLM:\SOFTWARE\Veeam\Veeam Backup and Replication"
  13. PathValueName = "CorePath"
  14. ExeName = "Veeam.Backup.Manager.exe"
  15. DisplayName = "Veeam Backup & Replication Server"
  16. },
  17. @{
  18. Name = "EM"
  19. RegistryPath = "HKLM:\SOFTWARE\Veeam\Veeam Backup Reporting"
  20. PathValueName = "ServicePath"
  21. ExeName = "Veeam.Backup.EnterpriseService.exe"
  22. DisplayName = "Veeam Backup Enterprise Manager"
  23. }
  24. )
  25.  
  26. function Get-VeeamUninstallKey {
  27. param (
  28. [Parameter(Mandatory = $true)]
  29. [string]$DisplayName
  30. )
  31.  
  32. foreach ($path in $uninstallPaths) {
  33. $key = Get-ChildItem $path -ErrorAction SilentlyContinue | ForEach-Object {
  34. $props = Get-ItemProperty $_.PsPath -ErrorAction SilentlyContinue
  35. if ($props.DisplayName -eq $DisplayName) { $_.PsPath }
  36. } | Select-Object -First 1
  37.  
  38. if ($key) {
  39. return $key
  40. }
  41. }
  42.  
  43. return $null
  44. }
  45.  
  46. function Convert-ToVersionObject {
  47. param (
  48. [string]$VersionString
  49. )
  50.  
  51. if (-not $VersionString) {
  52. return $null
  53. }
  54.  
  55. try {
  56. return [version]($VersionString -replace '[^\d\.]', '')
  57. }
  58. catch {
  59. return $null
  60. }
  61. }
  62.  
  63. $processedCount = 0
  64.  
  65. foreach ($product in $veeamProducts) {
  66. Write-Host ""
  67. Write-Host "=== Processing $($product.DisplayName) ==="
  68.  
  69. $installPath = (Get-ItemProperty -Path $product.RegistryPath -Name $product.PathValueName -ErrorAction SilentlyContinue).$($product.PathValueName)
  70. if (-not $installPath) {
  71. Write-Host "$($product.Name) not found in registry path $($product.RegistryPath). Skipping." -ForegroundColor Cyan
  72. continue
  73. }
  74.  
  75. $exePath = Join-Path $installPath $product.ExeName
  76. if (-not (Test-Path $exePath)) {
  77. Write-Warning "$($product.ExeName) not found at: $exePath"
  78. continue
  79. }
  80.  
  81. $newVersion = (Get-Item $exePath).VersionInfo.ProductVersion
  82. if (-not $newVersion) {
  83. Write-Warning "Could not determine file version from: $exePath"
  84. continue
  85. }
  86.  
  87. Write-Host "Detected version from file: $newVersion"
  88.  
  89. $veeamUninstallKey = Get-VeeamUninstallKey -DisplayName $product.DisplayName
  90. if (-not $veeamUninstallKey) {
  91. Write-Warning "Could not find Uninstall entry for '$($product.DisplayName)'."
  92. continue
  93. }
  94.  
  95. $currentRegVersion = (Get-ItemProperty -Path $veeamUninstallKey -ErrorAction SilentlyContinue).DisplayVersion
  96. Write-Host "Registry currently lists version: $currentRegVersion"
  97.  
  98. $currentVersionObject = Convert-ToVersionObject -VersionString $currentRegVersion
  99. $newVersionObject = Convert-ToVersionObject -VersionString $newVersion
  100.  
  101. if (-not $currentRegVersion) {
  102. Write-Host "Registry version is empty. Updating registry..." -ForegroundColor Yellow
  103. Set-ItemProperty -Path $veeamUninstallKey -Name DisplayVersion -Value $newVersion
  104. Write-Host "Registry updated successfully at:`n $veeamUninstallKey" -ForegroundColor Green
  105. $processedCount++
  106. continue
  107. }
  108.  
  109. if ($currentRegVersion -eq $newVersion) {
  110. Write-Host "Versions match. No update needed." -ForegroundColor Cyan
  111. $processedCount++
  112. continue
  113. }
  114.  
  115. if ($currentVersionObject -and $newVersionObject) {
  116. if ($newVersionObject -gt $currentVersionObject) {
  117. Write-Host "Newer version detected ($newVersion > $currentRegVersion). Updating registry..." -ForegroundColor Yellow
  118. Set-ItemProperty -Path $veeamUninstallKey -Name DisplayVersion -Value $newVersion
  119. Write-Host "Registry updated successfully at:`n $veeamUninstallKey" -ForegroundColor Green
  120. }
  121. else {
  122. Write-Host "Registry version ($currentRegVersion) is equal or newer. No update needed." -ForegroundColor Cyan
  123. }
  124. }
  125. else {
  126. Write-Host "Version format could not be compared numerically. Updating registry to file version." -ForegroundColor Yellow
  127. Set-ItemProperty -Path $veeamUninstallKey -Name DisplayVersion -Value $newVersion
  128. Write-Host "Registry updated successfully at:`n $veeamUninstallKey" -ForegroundColor Green
  129. }
  130.  
  131. $processedCount++
  132. }
  133.  
  134. if ($processedCount -eq 0) {
  135. Write-Warning "No supported Veeam installations were processed."
  136. }
  137.  
  138. Write-Host "`n=== Completed ==="
  139.  
Advertisement
Add Comment
Please, Sign In to add comment