Vbscript with input box to seach AD for user then change 1 atribute for that user

Side
Side used Ask the Experts™
on
Hi,

I have been trying to create a VBscript that will prompt for a username, Then Seach AD for the user
once the user is found give the option to change "msRTCSIP-OptionFlags" to  272

i just cant seem to get my head around using VBS with AD can anyone help?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Are you looking for something like this.... ?
Const ADS_PROPERTY_UPDATE = 2 
Set objUser = GetObject _
   ("LDAP://cn=Last\, First,ou=department,ou,dc=example,dc=com") 
 
objUser.Put "msRTCSIP-OptionFlags", "272"
objUser.SetInfo

Open in new window

Author

Commented:
Quite close and thank you , the and as i say i cant really script to save my life, because its a task i do quite a lot , i wanted to be able to just type the user name in a input box at the start
This one may be a bit better. It'll still require error checking and all, but it will do what you want it to do.

Const ADS_PROPERTY_UPDATE = 2 
strUserIn = InputBox("Enter Username")
dn = SearchDistinguishedName(strUserIn)

Public Function SearchDistinguishedName(ByVal vSAN)
    ' Function:     SearchDistinguishedName
    ' Description:  Searches the DistinguishedName for a given SamAccountName
    ' Parameters:   ByVal vSAN - The SamAccountName to search
    ' Returns:      The DistinguishedName Name
    Dim oRootDSE, oConnection, oCommand, oRecordSet

    Set oRootDSE = GetObject("LDAP://rootDSE")
    Set oConnection = CreateObject("ADODB.Connection")
    oConnection.Open "Provider=ADsDSOObject;"
    Set oCommand = CreateObject("ADODB.Command")
    oCommand.ActiveConnection = oConnection
    oCommand.CommandText = "<LDAP://" & oRootDSE.get("defaultNamingContext") & _
        ">;(&(objectCategory=User)(samAccountName=" & vSAN & "));distinguishedName;subtree"
    Set oRecordSet = oCommand.Execute
    On Error Resume Next
    SearchDistinguishedName = oRecordSet.Fields("DistinguishedName")
    On Error GoTo 0
    oConnection.Close
    Set oRecordSet = Nothing
    Set oCommand = Nothing
    Set oConnection = Nothing
    Set oRootDSE = Nothing
End Function 

wscript.echo dn

Set objUser = GetObject ("LDAP://" & dn)
 
objUser.Put "msRTCSIP-OptionFlags", "272"
objUser.SetInfo
wscript.echo "Done"

Open in new window

Author

Commented:
Brilliant thank you

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial