Thread: change odbc
View Single Post
Old 11-23-2007   #5 (permalink)
AHartman


 
 

Re: change odbc

What if you only know the server name... they could use anything for a
datasource name.


"Leo Tohill" <LeoTohill@xxxxxx> wrote in message
news:1748AB4C-022F-482A-9135-9867F6D374CB@xxxxxx
Quote:

> 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.
>>
>>
My System SpecsSystem Spec