Powershell includes a psDrive that makes the registry look like a file
system, so this is pretty easy to do. The following two-liner works:
$def = Get-childItem -path "hklm:\software\odbc\odbc.ini" -include
"mydatasourcename" -recurse
set-itemproperty -path $def.PsPath -name "Server" -value "myNewServerName"
Explanation:
The first line uses the HKLM: PSDrive to access the registry. I couldn't
figure out a more direct way to get the exact key that is needed,so I had to
specify a partial path (out to ODBC.Ini) and then use -include to specify the
datasource name, and -recurse was required too. I'm sure I'm missing a
better way, but this works. The result of this command is that $def
contains a reference to a registry object that describes that registry entry.
(Or $null, if the specified value doesn't exist.)
The second line uses the set-itemproperty cmdlet to set the property named
"Server" to the value "myNewServerName".
Change "myDataSourceName" and"myNewServerName" to whatever you are using.
HTH,
Leo
"AHartman" wrote:
Quote:
> I recently moved some of my SQL databases to my new sql2005 box. Now I'm
> looking for a way to send a script to people that will change there ODBC
> connection to the new server.
>
> any way to script this?
>
>
> Thanks.
>
>