Monday, 12 June 2017

Powershell Script to update ODBC registry remotely

[System.Reflection.Assembly]::LoadWithPartialName('Microsoft.VisualBasic') | Out-Null
$regvalue = [Microsoft.VisualBasic.Interaction]::InputBox("Enter the ServerName", "Computer", "")

$Computer = 'TEST'
#$regvalue = 'Server1'

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
$regKey= $reg.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC_NAME1",$true)

$ODBC_NAME1= $regKey.getValue("Server","$regvalue")

$reg = [Microsoft.Win32.RegistryKey]::OpenRemoteBaseKey('LocalMachine', $computer)
$regKey= $reg.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC_NAME2",$true)

$ODBC_NAME2= $regKey.getValue("Server","$regvalue")

[System.Windows.Forms.MessageBox]::Show("ODBC_NAME1 : $ODBC_NAME1       ODBC_NAME1 : $ODBC_NAME2","TEST ODBC updated",[System.Windows.Forms.MessageBoxButtons]::OKCancel,[System.Windows.Forms.MessageBoxIcon]::Information)