Solved

VBScript command to change attributes for a user

Posted on 2014-02-03
6
166 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free eBook: Backup on AWS

Everything you need to know about backup and disaster recovery with AWS, for FREE!

Question has a verified solution.

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

Auditing domain password hashes is a commonly overlooked but critical requirement to ensuring secure passwords practices are followed. Methods exist to extract hashes directly for a live domain however this article describes a process to extract u…
A hard and fast method for reducing Active Directory Administrators members.
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…
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 to another domain controller. Log onto the new domain controller with a user account t…

724 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