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?
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.

Chris DentPowerShell 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

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
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
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
VB Script

From novice to tech pro — start learning today.