Exports "Members of" to "Notes" in AD

Hi Experts,

Could i get help for exporting content of "Members of"(screenshot 1) from AD user to "Notes"(screenshot 2) in AD.

Need VB script or batch file to perform this, where script should pull the user names from the notepad.
screenshot-1.JPG
screenshot-2.JPG
LVL 1
rajkiggalAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Sushil SonawaneCommented:
You can achieve this through AD manager plus provide by manageengine. It is free for 30 days trail version.

For info and download refer below link :

http://www.manageengine.com/products/ad-manager/download.html
0
RobSampsonCommented:
Hi, this VBScript should work for you.  It will read users.txt for samAccountName's, and write the memberOf values to the info attribute (the Notes field).  It writes a log file to users_processed.csv as well.

Regards,

Rob,

strInputFile = "Users.txt"
strOutputfile = "Users_Processed.csv"

If Right(LCase(WScript.FullName), 11) = "wscript.exe" Then
	Set objShell = CreateObject("WScript.Shell")
	objShell.Run "cscript """ & WScript.ScriptFullName & """", 1, False
	Set objShell = Nothing
	WScript.Quit
End If

Set objFSO = CreateObject("Scripting.FileSystemObject")
Const intForReading = 1
Const ADS_PROPERTY_CLEAR = 1

Set objInputFile = objFSO.OpenTextFile(strInputFile, intForReading, False)

Set adoCommand = CreateObject("ADODB.Command")
Set adoConnection = CreateObject("ADODB.Connection")
adoConnection.Provider = "ADsDSOObject"
adoConnection.Open "Active Directory Provider"
adoCommand.ActiveConnection = adoConnection

 ' Search entire Active Directory domain.
Set objRootDSE = GetObject("LDAP://RootDSE")

strDNSDomain = objRootDSE.Get("defaultNamingContext")
strBase = "<LDAP://" & strDNSDomain & ">"

strDetails = """Login Name"",""Old Notes"",""New Notes"""

While Not objInputFile.AtEndOfStream
	strUser = objInputFile.ReadLine
	
	WScript.Echo "Processing " & strUser
	
	strFilter = "(&(objectCategory=person)(objectClass=user)(samAccountName=" & strUser & "))"
	
	' Comma delimited list of attribute values to retrieve.
	strAttributes = "cn,ADsPath"
	
	' Construct the LDAP syntax query.
	strQuery = strBase & ";" & strFilter & ";" & strAttributes & ";subtree"
	adoCommand.CommandText = strQuery
	adoCommand.Properties("Page Size") = 100
	adoCommand.Properties("Timeout") = 30
	adoCommand.Properties("Cache Results") = False
	
	' Run the query.
	Set adoRecordset = adoCommand.Execute
	 
	' Enumerate the resulting recordset.
	Do Until adoRecordset.EOF
	    ' Retrieve values and display.
		strUserName = Replace(adoRecordset.Fields("cn").Value, "CN=", "")
		'WScript.Echo "Processing " & strUser
		Set objUser = Nothing
		Set objUser = GetObject(adoRecordset.Fields("ADsPath").Value)
		strOldNotes = objUser.Info
		If TypeName(objUser.memberof) = "Empty" Then
			strMemberOf = ""
		ElseIf TypeName(objUser.memberof) = "String" Then
			strMemberOf = objUser.memberof
		Else
			strMemberOf = Join(objUser.memberof, vbCrLf)
		End If
		If strMemberOf = "" Then
			objUser.PutEx ADS_PROPERTY_CLEAR, "info", 0
		Else
			objUser.Info = strMemberOf
		End If
		objUser.SetInfo
		strNewNotes = objUser.Info
		strDetails = strDetails & VbCrLf & """" & strUserName & """,""" & strOldNotes & """,""" & strNewNotes & """"
	    ' Move to the next record in the recordset.
	    adoRecordset.MoveNext
	Loop
	
	' Clean up.
	adoRecordset.Close
	Set adoRecordset = Nothing
Wend

adoConnection.Close

Set objOutputFile = objFSO.CreateTextFile(strOutputFile, True)
objOutputFile.Write strDetails
objOutputFile.Close
Set objOutputFile = Nothing

WScript.Echo "Done"
MsgBox "Done"

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rajkiggalAuthor Commented:
Thank you Rob and Larry.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Server 2003

From novice to tech pro — start learning today.