An invalid dn syntax has been specified - VBScript to rename a group in AD2000

Hi,

I am trying to write a VBscript that will rename a mail enabled group in AD 2000 and then amend some of the attributes. If I hard code the LDAP query it works fine, but when I try to use a variable for the input  of the group names it falls over at the below line  

objDomain.MoveHere "LDAP://cn=" & strCurrentName & ",ou=Distribution Lists,dc=domain,dc=net", "cn=" & strNewName &""

the error message is

Char: 1
Error: An invalid dn syntax has been specified
Code: 80072032
Source: (null)
dim strCurrentName, strNewName
 
strCurrentName = InputBox ("Group Name to be Renamed:","Enter Current Group Name")
  if strCurrentName = "" then
  wscript.quit
  end if
 
strNewName = InputBox ("New Name of Group:","Enter New Group Name")
  if strNewName = "" then
  wscript.quit
  end if
 
Set objDomain = GetObject("LDAP://cn=" & strCurrentName & ",ou=Distribution Lists,dc=domain,dc=net")
 
objDomain.MoveHere "LDAP://cn=" & strCurrentName & ",ou=Distribution Lists,dc=domain,dc=net", "cn=" & strNewName &""
 
set objuser = GetObject("LDAP://cn=" & strNewName & ",ou=Distribution Lists,dc=domain,dc=net")
 
objUser.sAMAccountName = strNewName
objuser.displayName = strNewName
objuser.mailNickname = strNewName
objUser.SetInfo
MsgBox("Finished")

Open in new window

kevarooAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Chris DentConnect With a Mentor PowerShell DeveloperCommented:

This bit:

Set objDomain = GetObject("LDAP://cn=" & strCurrentName & ",ou=Distribution Lists,dc=domain,dc=net")
 
Should be a connection to the container for the list, not the list itself.

e.g.

Set objOU = GetObject("LDAP://ou=Distribution Lists,dc=domain,dc=net")

objOU.MoveHere "LDAP://cn=" & strCurrentName & ",ou=Distribution Lists,dc=domain,dc=net", "cn=" & strNewName
 
Otherwise you're attempting to move the object to be a child of the existing object.

Chris
0
 
kevarooAuthor Commented:
Cheers Chris your solution is spot on

Kev
0
 
kevarooAuthor Commented:
Thanks alot Chris,

Your soltuion works fine.

Kev
0
 
Chris DentPowerShell DeveloperCommented:

Always a pleasure :)

Chris
0
All Courses

From novice to tech pro — start learning today.