SCCM – VBScript – Return Data from SCCM DB No DSN

email me

Still working on this…

I’m going to be creating a small app to manage things like Bitlocker and Remote Support. The first step is to connect and use existing data from the SCCM database.

So far, it does connect and return specific elements from the database. Next, is to create a simple interface.

Note, I’m using the below to return Bitlocker Passwords…ones I stored in the SCCM DB using MOFs.

on error resume next 

Set Connection = CreateObject("ADODB.Connection")
Set Recordset = CreateObject("ADODB.Recordset")
Set filsSysObj = CreateObject("Scripting.FileSystemObject")

Connection.ConnectionString = "Provider=SQLOLEDB;Data Source=YourServer\TheInstanceIfYouHaveOne;Initial Catalog=CM_SiteCodeHere;Integrated Security=SSPI;"
Connection.open

'the sql command...for a custom field created from MOFs
sqlQuery = "SELECT * FROM dbo.Custom_Custom_DATA"

set data = Connection.execute(sqlQuery)

'output of my data
Set output = filsSysObj.OpenTextFile("output.csv", 8, True)

'cycle through the records, outputting specific elements 
do until data.EOF

	MachineID = data.Fields(0).Value 
	CDrive = data.Fields(6).Value
	DDrive = data.Fields(7).Value
	Output.Write MachineID & "," & CDrive & "," & DDrive
	Output.Write vbNewLine

	data.MoveNext
loop

'clean up
output.Close
Connection.Close