yellowartist
IS-IT--Management
Is it possible using VBScript to modify the CN, Name, and Distinguished name for a list of users in Active Directory.
I am trying to write a script to use when we separate employees. The standard now is to put the date they left infront of their name in active directory. I can get the display name to change but it is not changing it when browing ADUC for it.
Please assist...
Here is my script so far but I get an error every time....
The error is:
Error: "The directory service cannot perform the requested operation on the RDN attribute of an object."
"Code: 8072016
**Note** I have modified some information to protect company information**
Thanks for any assistance!
****************************************
Option Explicit
'on error resume next
Dim objUser, objShell
Dim objExcel, objSpread, intRow, intCol
Dim strUser, strSheet, strDate
Dim strCN, strSam, strDisplay, strName, strDN
Dim strmail, strUPN, strextA5
Dim objFSO, objFolder, objFileShare, strDest, strougroup, objgroup
Dim Inputprompt, strsn
strSheet = "path to spreadsheet"
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 1
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
strCN = Trim(objExcel.Cells(intRow, 1).Value)
strSam = Trim(objExcel.Cells(intRow, 2).Value)
strDisplay = Trim(objExcel.Cells(intRow, 3).Value)
strName = Trim(objExcel.Cells(intRow, 4).Value)
strDN = Trim(objExcel.Cells(intRow, 5).Value)
strmail = Trim(objExcel.Cells(intRow, 6).Value)
strextA5 = Trim(objExcel.Cells(intRow, 7).Value)
strUPN = Trim(objExcel.Cells(intRow, 8).Value)
strsn = Trim(objExcel.Cells(intRow, 10).Value)
strDate = "08/01/07 "
strougroup = "Group"
'Build the actual User from data in strSheet.
'Const ADS_PROPERTY_APPEND = 3
Set objUser = GetObject("LDAP://" & strdn)
'Wscript.echo "LDAP://" & strdn
objUser.Put "sAMAccountName", ("1" & strSam)
objUser.Put "DisplayName", (strDate & strdisplay)
objUser.Put "sn", (strsn)
objUser.Put "userPrincipalName", ("1" & strUPN)
objUser.Put "extensionAttribute5", "EXEMPT"
objUser.SetPassword "i5A2sj*!"
objuser.setInfo
' objUser.Put "cn", (strDate & strcn)
' objUser.Put "Name", (strDate & strname)
' objUser.Put "distinguishedName", (strDate & strdn)
objuser.setInfo
'add new Primary Address
objuser.PutEx 3, "proxyAddresses", Array("smtp:" & "del" & strmail)
objuser.setInfo
'Delete Old Primary
objuser.PutEx 4, "ProxyAddresses", Array("SMTP:" & strmail)
objuser.Put "mail", ("del" & strmail)
objuser.setInfo
'Hide From GAL
' objuser.put "msExchangeHideFromAddressLists", True
objUser.SetInfo
' Add to Group
If strougroup = False Then
Set objgroup = getobject("LDAP://" & Strougroup)
objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array(strdn)
objGroup.SetInfo
End If
' Increment to next user.
intRow = intRow + 1
Loop
Wscript.Echo "Done"
objExcel.Quit
WScript.Quit
I am trying to write a script to use when we separate employees. The standard now is to put the date they left infront of their name in active directory. I can get the display name to change but it is not changing it when browing ADUC for it.
Please assist...
Here is my script so far but I get an error every time....
The error is:
Error: "The directory service cannot perform the requested operation on the RDN attribute of an object."
"Code: 8072016
**Note** I have modified some information to protect company information**
Thanks for any assistance!
****************************************
Option Explicit
'on error resume next
Dim objUser, objShell
Dim objExcel, objSpread, intRow, intCol
Dim strUser, strSheet, strDate
Dim strCN, strSam, strDisplay, strName, strDN
Dim strmail, strUPN, strextA5
Dim objFSO, objFolder, objFileShare, strDest, strougroup, objgroup
Dim Inputprompt, strsn
strSheet = "path to spreadsheet"
' Open the Excel spreadsheet
Set objExcel = CreateObject("Excel.Application")
Set objSpread = objExcel.Workbooks.Open(strSheet)
intRow = 1
' Here is the 'DO...Loop' that cycles through the cells
' Note intRow, x must correspond to the column in strSheet
Do Until objExcel.Cells(intRow,1).Value = ""
strCN = Trim(objExcel.Cells(intRow, 1).Value)
strSam = Trim(objExcel.Cells(intRow, 2).Value)
strDisplay = Trim(objExcel.Cells(intRow, 3).Value)
strName = Trim(objExcel.Cells(intRow, 4).Value)
strDN = Trim(objExcel.Cells(intRow, 5).Value)
strmail = Trim(objExcel.Cells(intRow, 6).Value)
strextA5 = Trim(objExcel.Cells(intRow, 7).Value)
strUPN = Trim(objExcel.Cells(intRow, 8).Value)
strsn = Trim(objExcel.Cells(intRow, 10).Value)
strDate = "08/01/07 "
strougroup = "Group"
'Build the actual User from data in strSheet.
'Const ADS_PROPERTY_APPEND = 3
Set objUser = GetObject("LDAP://" & strdn)
'Wscript.echo "LDAP://" & strdn
objUser.Put "sAMAccountName", ("1" & strSam)
objUser.Put "DisplayName", (strDate & strdisplay)
objUser.Put "sn", (strsn)
objUser.Put "userPrincipalName", ("1" & strUPN)
objUser.Put "extensionAttribute5", "EXEMPT"
objUser.SetPassword "i5A2sj*!"
objuser.setInfo
' objUser.Put "cn", (strDate & strcn)
' objUser.Put "Name", (strDate & strname)
' objUser.Put "distinguishedName", (strDate & strdn)
objuser.setInfo
'add new Primary Address
objuser.PutEx 3, "proxyAddresses", Array("smtp:" & "del" & strmail)
objuser.setInfo
'Delete Old Primary
objuser.PutEx 4, "ProxyAddresses", Array("SMTP:" & strmail)
objuser.Put "mail", ("del" & strmail)
objuser.setInfo
'Hide From GAL
' objuser.put "msExchangeHideFromAddressLists", True
objUser.SetInfo
' Add to Group
If strougroup = False Then
Set objgroup = getobject("LDAP://" & Strougroup)
objGroup.PutEx ADS_PROPERTY_APPEND, "member", Array(strdn)
objGroup.SetInfo
End If
' Increment to next user.
intRow = intRow + 1
Loop
Wscript.Echo "Done"
objExcel.Quit
WScript.Quit