Solved

VBScript command to change attributes for a user

Posted on 2014-02-03
6
161 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Mapping Drives using Group policy preferences Are you still using old scripts to map your network drives if so this article will show you how to get away for old scripts and move toward Group Policy Preference for mapping them. First things f…
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…
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 Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

863 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

26 Experts available now in Live!

Get 1:1 Help Now