Ask a questionAsk a question
 

AnswerAccess SCCM database from VB script during OSD build.

  • Monday, October 19, 2009 11:37 AMDowery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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

  • Thursday, October 22, 2009 12:25 PMGarth JonesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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/

All Replies

  • Monday, October 19, 2009 12:08 PMcjp421 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    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
    
  • Monday, October 19, 2009 12:27 PMDowery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Monday, October 19, 2009 12:38 PMcjp421 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Has Code

    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...

    objConnection.Open _
        "Provider=SQLOLEDB;Data Source=" & DataSource & ";" & _
            "Initial Catalog=" & database & ";" & _
                "Integrated Security = SSPI;"
    
    Change your connection string to the above... see if that works as intended.
  • Monday, October 19, 2009 1:28 PMDowery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    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.
  • Tuesday, October 20, 2009 2:01 PMcjp421 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    I didn't think of that... what is preventing you from using SQL authentication?

  • Thursday, October 22, 2009 8:51 AMDowery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     

    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.

  • Thursday, October 22, 2009 12:25 PMGarth JonesMVPUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    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/
  • Friday, November 06, 2009 7:23 AMDowery Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Sorry for taking a while to come back.  Thanks Garth, I'll give that a try.