1
0
Files
odbc-migration-kit/restore-ODBC.ps1
Eugene Amos 912d24e0c6 ODBC scripts
- Fix and optimize export script for ODBC DSNs, registry keys, and driver inventory.
- Fix bug in the restore ODBC DSNs and registry keys scripts, ensuring compatibility with different Windows architectures.
2025-10-10 09:59:13 -07:00

116 lines
4.0 KiB
PowerShell
Raw Permalink Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<#
.SYNOPSIS
Restore ODBC DSNs and registry keys, and identify missing drivers.
.DESCRIPTION
- Extracts ODBC_Backup.zip into C:\ODBC_Migration\restore
- Imports all .reg and .xml files
- Recreates DSNs
- Compares exported vs installed ODBC drivers
- Displays missing drivers with official vendor download links
- Logs all operations
#>
# ===========================
# CONFIGURATION
# ===========================
$BaseDir = "C:\ODBC_Migration"
$ZipFile = Join-Path $BaseDir "ODBC_Backup.zip"
$ExtractDir = Join-Path $BaseDir "restore"
$LogFile = Join-Path $BaseDir ("restore_log_" + (Get-Date -Format "yyyyMMdd_HHmm") + ".txt")
# ===========================
# PREP
# ===========================
New-Item -ItemType Directory -Path $ExtractDir -Force | Out-Null
Start-Transcript -Path $LogFile -Append
Write-Host "`n=== ODBC RESTORE STARTED ===`n" -ForegroundColor Cyan
# ===========================
# STEP 1: EXTRACT ZIP PACKAGE
# ===========================
if (-not (Test-Path $ZipFile)) {
Write-Error "Cannot find ODBC_Backup.zip in $BaseDir"
Stop-Transcript
exit 1
}
Write-Host "Extracting archive..."
Expand-Archive -Path $ZipFile -DestinationPath $ExtractDir -Force
# ===========================
# STEP 2: IMPORT REGISTRY KEYS
# ===========================
Write-Host "Importing registry keys..."
$regFiles = Get-ChildItem $ExtractDir -Filter *.reg
foreach ($reg in $regFiles) {
Write-Host " -> $($reg.Name)"
reg import $reg.FullName | Out-Null
}
# ===========================
# STEP 3: RESTORE DSNs
# ===========================
$xmlPath = Join-Path $ExtractDir "odbc_dsns.xml"
if (Test-Path $xmlPath) {
Write-Host "Recreating DSNs from XML..."
$dsns = Import-Clixml $xmlPath
foreach ($dsn in $dsns) {
try {
Add-OdbcDsn @dsn -ErrorAction Stop
Write-Host " + Added DSN: $($dsn.Name)" -ForegroundColor Green
} catch {
Write-Warning " ! Failed to add DSN: $($dsn.Name) - $_"
}
}
} else {
Write-Warning "No odbc_dsns.xml found in package."
}
# ===========================
# STEP 4: VERIFY DRIVER PRESENCE
# ===========================
Write-Host "`nChecking for missing ODBC drivers..." -ForegroundColor Yellow
$exportCsv = Join-Path $ExtractDir "odbc_driver_product_map.csv"
if (-not (Test-Path $exportCsv)) {
Write-Warning "No driver map CSV found — skipping driver comparison."
} else {
$needed = Import-Csv $exportCsv
$installed = Get-OdbcDriver | Select-Object -ExpandProperty Name
$missing = @()
foreach ($n in $needed) {
if ($n.OdbcDriverName -and ($installed -notcontains $n.OdbcDriverName)) {
$missing += $n
}
}
if ($missing.Count -gt 0) {
Write-Host "`n=== Missing ODBC Drivers Detected ===`n" -ForegroundColor Red
foreach ($m in $missing) {
$dl = $m.DownloadURL
if ($dl -match '^https?') {
Write-Host (" - {0} ({1})`n Download: {2}" -f $m.OdbcDriverName, $m.Platform, $dl) -ForegroundColor Yellow
} else {
Write-Host (" - {0} ({1})`n Download: [Manual search required]" -f $m.OdbcDriverName, $m.Platform) -ForegroundColor DarkYellow
}
}
Write-Host "`nSee the detailed Markdown report for clickable links:" -ForegroundColor Cyan
Write-Host " $($ExtractDir)\ODBC_Migration_Report.md`n" -ForegroundColor White
} else {
Write-Host "All previously detected drivers are installed." -ForegroundColor Green
}
}
# ===========================
# STEP 5: SUMMARY
# ===========================
Write-Host "`n=== RESTORE COMPLETE ===`n" -ForegroundColor Cyan
Write-Host "✔ Registry and DSNs restored"
Write-Host "✔ Logs saved to: $LogFile"
Write-Host "✔ Extracted files in: $ExtractDir"
Write-Host "`nNext Steps:"
Write-Host "1⃣ Verify DSNs in ODBC Administrator (32-bit and 64-bit)."
Write-Host "2⃣ Install any missing drivers listed above."
Write-Host "3⃣ Re-run this script if needed after driver installation.`n"
Stop-Transcript