I'm looking for a way to possible have a script get all system DSNs from a server as well as get all SQL databases on an instance and compare the two to make sure that all DSNs are installed on this server. I have a script to grab the DSNs and I have a separate script to get the SQL DB's.
DSN script:
Const HKEY_LOCAL_MACHINE = &H80000002
strComputer = "."
Set objRegistry = GetObject("winmgmts:\\" & strComputer & "\root\default:StdRegProv")
strKeyPath = "SOFTWARE\ODBC\ODBC.INI\ODBC DATA SOURCES"
objRegistry.EnumValues HKEY_LOCAL_MACHINE, strKeyPath, arrValueNames, arrValueTypes
For i = 0 to Ubound(arrValueNames)
strValueName = arrValueNames(i)
If LEFT(strValueName, 2) = "SB" Then
objRegistry.GetStringValue HKEY_LOCAL_MACHINE, strKeyPath, strValueName, strValue
strDSN = strDSN & strValueName & VBCRLF
End If
Next
wscript.echo strDSN
SQL DB script:
dim sServer, sConn, oConn, colDatabases, sDatabaseName, sUser, sPassword, strQry, run, rslt
sDatabaseName="Master"
sServer="."
sUser="."
sPassword="."
sConn="provider=sqloledb;data source=" & sServer & ";initial catalog=" & sDatabaseName
Set oConn = CreateObject("ADODB.Connection")
oConn.Open sConn, sUser, sPassword
strQry = "select name from sys.databases where name like 'sb%'"
set run = oConn.execute(strQry)
run.MoveFirst
Do Until run.EOF
rslt = rslt & "Database: " & run("name") & VBCRLF
run.MoveNext
Loop
MsgBox rslt
oConn.Close
I can run these two separately and compare them myself but I'd like to be able to consolidate them and have the script compare them and give feedback on what may be missing.