?
Solved

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

Posted on 2013-05-13
3
Medium Priority
?
761 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 2000 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

Containers & Docker to Create a Powerful Team

Containers are an incredibly powerful technology that can provide you and/or your engineering team with huge productivity gains. Using containers, you can deploy, back up, replicate, and move apps and their dependencies quickly and easily.

Question has a verified solution.

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

Active Directory security has been a hot topic of late, and for good reason. With 90% of the world’s organization using this system to manage access to all parts of their IT infrastructure, knowing how to protect against threats and keep vulnerabil…
Let's recap what we learned from yesterday's Skyport Systems webinar.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Suggested Courses

770 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