Solved

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

Posted on 2013-05-13
3
741 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
[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
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

While rebooting windows server 2003 server , it's showing "active directory rebuilding indices please wait" at startup. It took a little while for this process to complete and once we logged on not all the services were started so another reboot is …
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
The viewer will learn how to count occurrences of each item in an array.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

726 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