Connecting to DC and Change settings

We are trying to create a vbscript which will be used by helpdesk team to add the PC name to the Logon To tab of one user property. The challange is to connect to a Domain Controller based on location and do the changes so that user need not wait for replication. The below script is there which will do the same but only issue we are facing is that I want the user to specify the location in the input box and based on input the DC will be connected. When the user is providing the input for the location it is not able to recognise the same as whatever is written by User


============================================================
Const ADS_PROPERTY_UPDATE = 2
Dim vInput
vInput = InputBox("Enter a HostName","WorkStation")
Dim Location
Location = InputBox("Enter the Location","Location")
Wscript.echo LOcation
If Location =Location1 Then
Set objUser =GetObject("LDAP://DC1/CN=User1,OU=OU1,DC=Domain,DC=Com")
Elseif Location = Location2 Then
Set ObjUser=GetObject("LDAP://DC2/CN=User1,OU=OU1,DC=Domain,DC=Com"")
objUser.Put "userWorkstations", vInput
objUser.SetInfo
End if
============================================================

PLease suggest if we can do something for the same.

Thanks and Regards,

Neo_78Asked:
Who is Participating?
 
prashanthdConnect With a Mentor Commented:
Try the following
Const ADS_PROPERTY_UPDATE = 2
Dim vInput
vInput = InputBox("Enter a HostName","WorkStation")
Dim Location
Location = InputBox("Enter the Location","Location")
WScript.echo Location
If LCase(Location) = lcase("Location1") Then
    Set objUser =GetObject("LDAP://DC1/CN=User1,OU=OU1,DC=Domain,DC=Com")
    objUser.Put "userWorkstations", vInput
    objUser.SetInfo
ElseIf LCase(Location) = lcase("Location2") Then
    Set ObjUser=GetObject("LDAP://DC2/CN=User1,OU=OU1,DC=Domain,DC=Com"")
    objUser.Put "userWorkstations", vInput
    objUser.SetInfo
End If

Open in new window

0
 
sirbountyCommented:
If it's merely a number on the DC, you can skip the if logic and shorten it a bit...
Const ADS_PROPERTY_UPDATE = 2
Dim vInput : vInput = InputBox("Enter a HostName","WorkStation")
Dim Location : Location = Right(InputBox("Enter the Location","Location"), 1)
Dim objUser : Set objUser =GetObject("LDAP://DC" & Location & "/CN=User1,OU=OU1,DC=Domain,DC=Com")
objUser.Put "userWorkstations", vInput
objUser.SetInfo

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.