Solved

VBScript command to change attributes for a user

Posted on 2014-02-03
6
159 Views
Last Modified: 2014-11-11
I am trying to write a script that will retrieve a user from AD and then change various attributes.  I am accessing the user by their cn and looking to change sAMAccount, userPrincipalName and scriptPath.

I have a number of users to change so currently am trying to user a variable for the cn in the
command

Set objUser = GetObject(strStringToExecute)

Open in new window


where strStringToExecute is built as follows
strStringToExecute = char(34) & "LDAP://cn=" & strNameToChange & ", " & strOU & Char(34)

Open in new window

When i write the string out, it looks right so the question is can GetObject accept the variable?

The specific block of vb code is listed below
objCommand.CommandText = _
	"SELECT distinguishedName FROM 'LDAP://DC=ad,DC=brooksbrothersgroup,dc=com' WHERE objectCategory='user' " & _
	"AND cn = '" & strNameToChange & "'"

Set objRecordSet = objCommand.Execute

if objRecordSet.RecordCount > 0 then

	strStringToExecute = char(34) & "LDAP://cn=" & strNameToChange & ", " & strOU & Char(34)
	Set objUser = GetObject(strStringToExecute)

	objUser.userPrincipalName = txtnewUPN(UsersToChangeCtr)
	objUser.sAMAccountName = txtnewSMA(UsersToChangeCtr)
	objUser.scriptPath = txtsp(UsersToChangeCtr)

	objUser.SetInfo

Open in new window


If not, I would welcome advice on how to achieve this.
0
Comment
Question by:amiurchaudry
6 Comments
 
LVL 65

Accepted Solution

by:
RobSampson earned 500 total points
ID: 39834843
For your GetObject call, you should be able to use
Set objUser = GetObject("LDAP://" & objRecordset("distinguishedName"))

That would bind to the user you just found, and you can continue to change properties from there.

Regards,

Rob.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Not long ago I saw a question in the VB Script forum that I thought would not take much time. You can read that question (Question ID  (http://www.experts-exchange.com/Programming/Languages/Visual_Basic/VB_Script/Q_28455246.html)28455246) Here (http…
Find out how to use Active Directory data for email signature management in Microsoft Exchange and Office 365.
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now