I think I have wasted enough of one day. I have not been able to find any script close to this, except for modification of user accounts. There are vague references to Powershell solutions which will be great if that is what is needed, but I am hoping for a VBS solution. I am being put into a situation where I am essentially being forced to learn scripting.
I need to edit this to use the sAMAccountNames in the input file to query over 1,700 groups (distribution lists) and MODIFY the displayName, distinguishedName, CN, as well as the sAMAccountName. The output file results in generated text but it seems it is simply output; not an indication that groups were modified. The displayNames are blank currently but the distinguishedNames and the sAMAccountNames have values. I was told that after querying for the sAMAccountName, I could change the line or add a line to query and bind to for CN, in order to modify the sAMAccounNames.
Ideally, I need to remove the "z-" that is used to begin the sAMAccountNames as well as the DN, and CN for all these groups and then use the sAMAccountNames to write the vaules for displayNames with (XXXX) after them.. and then "establish email addresses" by specifying the second part of the SMTP address to be @xxx.xxxxx.xxx. But I would be content for now just to get a solution for the first paragraph. Thank you!
On Error Resume Next
Const ForReading = 1
Const ForWriting = 2
Const ForAppending = 8
Const ADS_SCOPE_ONELEVEL = 1
Const ADS_SCOPE_SUBTREE = 2
Const ADS_UF_DONT_EXPIRE_PASSWD = &h10000
Const ADS_PROPERTY_CLEAR = 1
Set objConnection = CreateObject("ADODB.Connection")
objConnection.Provider = "ADsDSOObject"
objConnection.Open "Active Directory Provider"
Set objCommand = CreateObject("ADODB.Command")
Set objCommand.ActiveConnection = objConnection
objCommand.Properties("Page Size") = 1000
Set objRootLDAP = GetObject("LDAP://RootDSE")
strDNSDomain = objRootLDAP.Get("DefaultNamingContext")
'Here read from the source file to get a sAMAccountName and then loop for each one
strInputFile = inputbox("Please enter the Mapping File", "Input")
'This will be the extract of sAMAccountName
strOutputFile = inputbox("Please enter the Output File", "Input")
'This will be the resulting output file that contains the Accounts processed
Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objTextFile = objFSO.OpenTextFile(strInputFile, ForReading)
Set objFile = objFSO.GetFile(strInputFile)
If objfso.fileexists(strinputfile) then
Set objCreateFile = objFSO.CreateTextFile(strOutputFile)
'check to see if the file is empty
If objFile.Size > 0 Then
Do Until objTextFile.AtEndOfStream
strNextLine = objTextFile.Readline
arrUidList = Split(strNextLine , "*")
'here we set the ldap query
objCommand.CommandText= "<LDAP://dc=XXX,dc=XXXXX,dc=XXX>; (&(objectclass=group)(sAMAccountName=" & arrUidList(0) & ")); name,cn,distinguishedName,displayName;subtree"
Set ObjRecordSet = objCommand.Execute
'Bind using distinguishedName
While Not objRecordSet.EOF
'go to the next looked up uid but there should never be one
'Enable the Account
set objUser = GetObject("LDAP://" & strUserDN)
'can set the displayName to specified value in file
'this appends a value to existing displayName
'be sure and test with sample file
'option to update sAMAcountName using second column in mapping file
OldName = objuser.displayname
objuser.displayname = OldName & " (XXXX)"
OldNamecn = objuser.cn
objuser.cn = OldNamecn & " (XXXX)"
Set objOutputFile = objFSO.OpenTextFile(strOutputFile, ForAppending, True)
'Here we would output the variables that we looked up
objOutputFile.WriteLine(strcovname & "," & objuser.displayname & "," & objuser.cn)
OldName = ""
OldNamecn = ""
arrUidList = ""
'end of read loop
'finalize the connection
' if the file was empty let us know
Wscript.Echo "The file is empty."
Wscript.echo "Accounts Updated!"
Wscript.Echo "Mapping file does not exist."