Registered member login:
Register Now
Altirigos » Deployment Solution » Scripting/Tools/Docs » Query SQL eXpress database

» Current Poll
Do you leave the Aclient enabled?
YES - 82.31%
107 Votes
NO - 17.69%
23 Votes
Total Votes: 130
You may not vote on this poll.
» Stats
Members: 9,496
Threads: 11,750
Posts: 55,298
Top Poster: Nick (4,981)
Welcome our newest member, JessicaD
» Online Users: 57
2 members and 55 guests
Juice_IFF, Zizio82
Most users online at once 294, 06-30-2007 at 12:24 PM.
» March 2010
S M T W T F S
28 1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31 123
Reply
Old 03-12-2009, 05:11 PM   #1 (permalink)
 
Status: Junior Altiris Admin
Join Date: 02-26-2008
Location: Netherlands
Posts: 18


Query SQL eXpress database

I would like to, using a vbs script, query the SQL DS eXpress database and create a table with information like computername, ip address, mac address.

Is there someone sho can help me out on this ?
pollewops is offline   Reply With Quote
Old 04-06-2009, 02:19 PM   #2 (permalink)
 
TRYDL's Avatar
 
Status: Super Altiris Admin
Join Date: 03-08-2006
Location: Baltimore, MD
Age: 29
Posts: 576


This came out of the MSFT script center

Quote:
Const adOpenStatic = 3
Const adLockOptimistic = 3

Set objConnection = CreateObject("ADODB.Connection")
Set objRecordSet = CreateObject("ADODB.Recordset")

objConnection.Open _
"Provider=SQLOLEDB;Data Source=MYExpressDBServer;" & _
"Trusted_Connection=Yes;Initial Catalog=express;" & _
"User ID=DOMAINNAME\USERNAME;Password=PASSWORD;"

objRecordSet.Open "SELECT * FROM Computer", _
objConnection, adOpenStatic, adLockOptimistic

objRecordSet.MoveFirst

Wscript.Echo objRecordSet.RecordCount
Anything particular you are looking for?
__________________
3rd Floor Garage Door Operator
TRYDL is offline   Reply With Quote
Old 04-07-2009, 02:53 AM   #3 (permalink)
 
Status: Junior Altiris Admin
Join Date: 02-26-2008
Location: Netherlands
Posts: 18


Thanks for the update. Maybe I can use that as well, but I found already something else.
See my script code below. This works perfect !

Quote:
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objShell = wscript.createobject ("WScript.Shell")
MyServer="<sql_db_server_name>"
Set DBCon = CreateObject("ADODB.Connection")
DBCon.Open "Provider=SQLOLEDB;Server=" & MyServer & ";database=eXpress;Trusted_Connection=yes"
strHeader = "computername,groupname,serial,macaddress,ipaddres s,computertype,manufacturer,model,ostype,lastupdat e"
wscript.echo strHeader
objReportFile.WriteLine strHeader
SQL = "select comp.computer_name,grp.name,comp.serial_num,n.mac_ addr,netw.ip_address,comp.prod_name,comp.manuf,com p.model_num,comp.os,ses.last_update from dbo.computer comp inner join dbo.nics n ON comp.computer_id = n.computer_id inner join dbo.computer_display netw ON comp.computer_id = netw.computer_id inner join dbo.computer_group grp ON comp.group_id = grp.group_id left join dbo.sessions ses ON comp.computer_id = ses.computer_id order by comp.computer_name asc"
Set TargetGUID = DBCon.Execute(SQL)
Do While TargetGUID.EOF = False
MyGUID = TargetGUID.Fields("computer_name").Value & "," & TargetGUID.Fields("name").Value & "," & TargetGUID.Fields("serial_num").Value & "," & TargetGUID.Fields("mac_addr").Value & "," & trim(TargetGUID.Fields("ip_address").Value) & "," & TargetGUID.Fields("prod_name").Value & "," & TargetGUID.Fields("manuf").Value & "," & TargetGUID.Fields("model_num").Value & "," & TargetGUID.Fields("os").Value & "," & TargetGUID.Fields("last_update").Value
wscript.echo MyGUID
select case TargetGUID.Fields("model_num").Value
case "098Ch"
AmountT5710 = AmountT5710 + 1
case "0A24h"
AmountT5720 = AmountT5720 + 1
case Else
AmountTOther = AmountTOther + 1
end select
AmountTOT = AmountTOT + 1
TargetGUID.MoveNext
Loop
DBCon.Close
pollewops is offline   Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Powered by vBadvanced CMPS v3.0 RC2

All times are GMT -4. The time now is 04:43 AM.


Powered by vBulletin® Version 3.7.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
vB.Sponsors
Altirigos