Solved

vbscript to copy a specific value from one attribute to another in Active Directory Users

Posted on 2013-05-13
3
725 Views
Last Modified: 2013-06-06
Hello,
I'm looking for a way a vbscript can access the Active Directory, go through all the users one by one, and for each of them copy the values in the "Assistant" attribute (can by any other attribute for example) and copy them over to the "Fax" attribute.

Any such thing?
0
Comment
Question by:johnnyjonathan
  • 2
3 Comments
 
LVL 42

Expert Comment

by:sedgwick
ID: 39161128
if u want in powersehll, here it is.

Import-Module ActiveDirectory  
cls
$copyFromProp = 'Assistant'
$copyToProp = 'Fax'
Get-ADUser -Filter * -Properties $copyFromProp,$copyToProp | %{
	$user = $_
	$replaceHashTable = New-Object HashTable 
	$replaceHashTable.Add($copyFromProp, $copyToProp) 
	Set-ADUser 'm.rivkin' -Replace $replaceHashTable
}

Open in new window

0
 
LVL 42

Accepted Solution

by:
sedgwick earned 500 total points
ID: 39161195
here in vb script:
'SearchAD.vbs
On Error Resume Next

sCopyPropFrom = "Assistant"
sCopyPropTo = "Fax"

Set objRootDSE = GetObject("LDAP://RootDSE")
strDNSDomain = objRootDSE.Get("defaultNamingContext")
strTarget = "LDAP://" & strDNSDomain
wscript.Echo "Starting search from " & strTarget

' Connect to Ad Provider
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"

Set objCmd = CreateObject("ADODB.Command")
Set objCmd.ActiveConnection = objConnection 

objCmd.CommandText = "SELECT " & sCopyPropFrom & ", " & sCopyPropTo & " FROM '" & strTarget & "' WHERE objectCategory = 'user'"

Const ADS_SCOPE_SUBTREE = 2
objCmd.Properties("Page Size") = 100
objCmd.Properties("Timeout") = 30
objCmd.Properties("Searchscope") = ADS_SCOPE_SUBTREE
objCmd.Properties("Cache Results") = False

Set objRecordSet = objCmd.Execute

objRecordSet.MoveFirst
Do Until objRecordSet.EOF
	sCopyPropFromVal = objRecordSet.Fields(sCopyPropFrom)
	sCopyPropToVal = objRecordSet.Fields(sCopyPropTo)
	Set objUser = GetObject ("LDAP://" & sCopyPropFromVal)
	wscript.Echo objUser.Name & " - Assign " & sCopyPropFromVal & " to property " & sCopyPropTo
	objUser.Put sCopyPropTo, sCopyPropFromVal
	objUser.SetInfo
	objRecordSet.MoveNext
Loop

Open in new window

0
 

Author Closing Comment

by:johnnyjonathan
ID: 39225460
Works like a charm! thanks a lot!
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Deploying a Microsoft Access application in a Citrix environment is not difficult but takes a few steps. However, Citrix system people are often of little help, as they typically know next to nothing about Access. The script provided here will take …
Learn the basics of if, else, and elif statements in Python 2.7. Use "if" statements to test a specified condition.: The structure of an if statement is as follows: (CODE) Use "else" statements to allow the execution of an alternative, if the …
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…

705 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

17 Experts available now in Live!

Get 1:1 Help Now