<# @Title = A script to migrate from RayVentory Portal to RayVentory Scan Engine @Author = Raynet GmbH @Version = 0.1 @Description = This script is supposed to adjust Config.xml files to fix obsolete hardcoded paths #> # Setting up logging Write-Host "Starting migration script" $tempFilePath = [System.IO.Path]::Combine($env:TEMP, "RVPtoRVSEmigration.log") Start-Transcript -Path $tempFilePath -NoClobber -Append Write-Host "PowerShell information" $PSVersionTable Write-Host "" try { # Extraction of RVP appdata storage from Registry $appdataPath = [string]::Empty; $programFilesPath = [string]::Empty; if ([Environment]::Is64BitProcess) { $appdataPath = Get-ItemProperty -Path "HKLM:\SOFTWARE\WOW6432Node\Raynet\RayVentoryPortal" -Name "AppDataPath" | Select-Object -ExpandProperty "AppDataPath" $programFilesPath = [Environment]::ExpandEnvironmentVariables("%ProgramFiles(x86)%") } else { $appdataPath = Get-ItemProperty -Path "HKLM:\SOFTWARE\Raynet\RayVentoryPortal" -Name "AppDataPath" | Select-Object -ExpandProperty "AppDataPath" $programFilesPath = [Environment]::ExpandEnvironmentVariables("%ProgramFiles%") } # Checking if configuration values are in place if ([string]::IsNullOrEmpty($appdataPath)) { Write-Warning -Message "RayVentory Portal configuration registry is missing. No migration will be done." [System.Environment]::Exit(1) } $configFilePath = [System.IO.Path]::Combine($appdataPath, "Raynet", "RayVentoryPortal", "Config", "Config.xml"); if (!(Test-Path($configFilePath))) { Write-Warning -Message "Configuration file not found. No migration will be done." [System.Environment]::Exit(1) } else { # Updating hardcoded paths Write-Host "Updating hardcoded paths" [xml]$configContent = Get-Content -Path $configFilePath -Encoding UTF8 $oratrackPath = $configContent.Configuration.OracleTrackerFolderPath; $ndtrackPath = $configContent.Configuration.NdtrackExecutablePath; $isRiwClassesEmpty = $false; $riwClassesPath = $configContent.Configuration.RIWClassesFile; if ([string]::IsNullOrEmpty($riwClassesPath)) { $isRiwClassesEmpty = $true; } $isContentChanged = $false if (!(Test-Path $oratrackPath) -and !($oratrackPath -eq ".\Contrib\Oratrack")) { Write-Warning "OraTrack configuration is invalid : $oratrackPath. Will be reset to default: .\Contrib\Oratrack" $oratrackPath = ".\Contrib\Oratrack"; $configContent.Configuration.OracleTrackerFolderPath = $oratrackPath; $isContentChanged = $true; } if (!(Test-Path $ndtrackPath) -and !($ndtrackPath -eq ".\Contrib\ndtrack\ndtrack.exe")) { Write-Warning "NdTrack configuration is invalid : $ndtrackPath. Will be reset to default: .\Contrib\ndtrack\ndtrack.exe" $ndtrackPath = ".\Contrib\ndtrack\ndtrack.exe"; $configContent.Configuration.NdtrackExecutablePath = $ndtrackPath; $isContentChanged = $true; } if (!$isRiwClassesEmpty -and !(Test-Path $riwClassesPath) -and !($riwClassesPath -eq ".\example.xml")) { $riwFileName = [System.IO.Path]::GetFileName($riwClassesPath); if ([string]::Equals($riwFileName, "example.xml")) { Write-Warning "Zero-Touch cusom inventory configuration file path is invalid: $riwClassesPath. It will be reset to default: .\example.xml" $riwClassesPath = ".\example.xml"; $configContent.Configuration.RIWClassesFile = $riwClassesPath; $isContentChanged = $true; } else { Write-Warning "Zero-Touch cusom inventory configuration file path is invalid. Please manually adjust the configuration." } } if ($isContentChanged) { # Making a backup of configuration file $configBackupPath = $configFilePath + ".old"; $nameNum = 1; $fullConfigBackupPath = $configBackupPath while (Test-Path $fullConfigBackupPath) { $fullConfigBackupPath = $configBackupPath + $nameNum; $nameNum += 1; } Write-Host "Making a backup of Config.xml: $fullConfigBackupPath" Copy-Item -Path $configFilePath -Destination $fullConfigBackupPath Write-Host "Writing changes back to Config.xml: $configFilePath"; Remove-Item -Path $configFilePath -Force $configContent.Save($configFilePath) Write-Host "Migration process was performed successfully" } else { Write-Host "No changes made to a configuration. Nothing will be written." } } } catch { Write-Warning "Migration failed. Check the log file." Write-Warning $_ } finally { Stop-Transcript }