Access SCCM database from VB script during OSD build.
I have entered some asset details into the SCCM database using a GUI that runs during the OSD task sequence that creates a noidmif. When clients are rebuilt I would like them to read this information from the SCCM database rather than ask for the information via the GUI. Is there any way to access the SCCM database via a VB script during the deployment? The issue I have is authenticating to a Windows mode SQL server when my script is running using a local account.
Cheers
Answers
- You don't need to re-install to change from Windows Auth. to SQL Auth., it is just a radio button to select and restarting of the service.
http://www.enhansoft.com/- Marked As Answer byYog Li - MSFTMSFT, ModeratorTuesday, November 03, 2009 9:52 AM
All Replies
Is the data you are trying to access stored in WMI on the ConfigMgr site server? If so, just query WMI, this can be done easily.
Otherwise...Dim Username, Password, DataSource, Database, Exceptions 'Provide Datasource, Database, Username, Password and query Datasource = "" Database = "" Username = "" Password = "" Exceptions = "" query = "" Const adOpenStatic = 3 Const adLockOptimistic = 3 Set objConnection = CreateObject("ADODB.Connection") Set objRecordSet = CreateObject("ADODB.Recordset") objConnection.Open _ "Provider=SQLOLEDB;Data Source=" & DataSource & ";" & _ "Initial Catalog=" & database & ";" & _ "User ID=" & Username & ";Password=" & password & ";" objRecordSet.Open query, objConnection, adOpenStatic, adLockOptimistic While not objRecordSet.eof For each field in objRecordSet.fields 'Do your data manipulation Next objRecordSet.movenext wend set objRecordSet = nothing
- Thanks for the response.
I've tried this, and it works fine with a database in SQL Authentication Mode, but when the database is in Windows mode I get the following error:
Login failed for user 'Account Name'. The user is not associated with a trusted SQL Server connection. Please correct me if I'm wrong... but the task sequence will be running as NT AUTHORITY\System.
If you use the "Run command line" task with "Run As..." specified, it may work using Windows authentication...Change your connection string to the above... see if that works as intended.objConnection.Open _ "Provider=SQLOLEDB;Data Source=" & DataSource & ";" & _ "Initial Catalog=" & database & ";" & _ "Integrated Security = SSPI;"- Yes, the account will be running in the system environment which I can't use to connect. Also, I cannot use the runas option within the task because this line cannot be used for tasks running within the pre-execution environment. The secondary logon service is not included in the boot image.
I didn't think of that... what is preventing you from using SQL authentication?
I've already built the SCCM environment on a SQL server configured to use Windows authentication. It would be too big, and risky, a job re-installing everything.
- You don't need to re-install to change from Windows Auth. to SQL Auth., it is just a radio button to select and restarting of the service.
http://www.enhansoft.com/- Marked As Answer byYog Li - MSFTMSFT, ModeratorTuesday, November 03, 2009 9:52 AM
- Sorry for taking a while to come back. Thanks Garth, I'll give that a try.

