?
Solved

VBScript command to change attributes for a user

Posted on 2014-02-03
6
Medium Priority
?
167 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
In the absence of a fully-fledged GPO Management product like AGPM, the script in this article will provide you with a simple way to watch the domain (or a select OU) for GPOs changes and automatically take backups when policies are added, removed o…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …
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 …
Suggested Courses

765 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