All Forums >> [Scripting] >> WSH & Client Side VBScript >> vbscript connection to sql server database Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
Is there any way to connect to a sql server 7 or 8 database.
My whole task is to create a script that will update user profiles in Active Directory. Now a universal update to the active directory is not that difficlut. But for testing I am trying to write a script that will just do the person that runs the script (yes the people that will run the script in this state all have admin rights). But my problem comes because I cant get the users full name (that is the way the cn object in out active directory can be accessed, unless there is another way to access the user object with the logon that would be great but as it stands I can use the Last, First to make the LDAP connection). Therefore I was thinking that I can connect to our database that has the login with their full name and then use that full name to connect to ldap and make the .profilePath change. Does anyone know how to connect to Ad with login??? If not can you give me an example on how to query a database in sqlserver 7.0 and then I'm good to go.
The following script will bind to a user object based on the supplied user logon name and displays the assocaited profile path which should be enough to get you started.
Make appropriate changes to the pat and domain variables to reflect the actual values used.
============================================================================================ Option Explicit Dim conn, cmd, rs, user, pat, domain
domain = "dc=ca,dc=pm,dc=com" pat = "userID"
Set conn = CreateObject("ADODB.Connection") Set cmd = CreateObject("ADODB.Command") conn.provider = "adsdsoobject" conn.open "active directory provider" cmd.activeconnection = conn cmd.commandtext = "<LDAP://" & domain & ">;(samaccountname=" & pat & ");distinguishedname;subtree" Set rs = cmd.Execute If rs.eof Then WScript.Echo "No user userID matched """ & pat & """ is found." Else Set user = GetObject("LDAP://" & rs("distinguishedname")) WScript.Echo user.Get("profilepath") End If