No announcement yet.

vbscript to update active directory on remote computer

  • Filter
  • Time
  • Show
Clear All
new posts

  • vbscript to update active directory on remote computer

    hi folks i am using the following script to update a user on the Active directory.
    Will it be possible to modify this script so that i could run it from another computer on my network
    Dim StringValue,aname,letter,Hundred_value,Increment_Value,i,k,mob,counter,old,arun,result,tel
    letter = "A"
    Hundred_value = 100 
    Counter =1
    arun =1 
    Set myFSO = CreateObject("Scripting.FileSystemObject")
    Set WriteStuff = myFSO.OpenTextFile("c:\resultA.txt", 8, True)
    tel = 100
    'The following loop updates the homephone without affecting the filter (phonenumber) 
    'of 13000 Batch A internal users
    do while arun > 0
     for k=100 to 1300 step 100 '1300
       for i=1 to 1000  
           aname = "UserBatch" & k & letter & i
           StringValue = "LDAP://cn=" & aname & ",ou=TestUsers, dc=ldap,dc=Mettoni,dc=com"
          WriteStuff.WriteLine(stringvalue & " " & i & " " & k)
           'Wscript.Echo stringvalue & " " & i & " " & k      
          Set objUser = GetObject (StringValue) 
           Wscript.Echo "ok"
           mob = mob  + 1
            objUser.Put "mobile", mob+2
           objUser.Put "pager", mob+1
           objUser.Put "homephone", mob+2
           objUser.Put "TelexNumber", mob+1
           objUser.PutEx ADS_PROPERTY_UPDATE,"mobile", Array(mob+2)
           objUser.PutEx ADS_PROPERTY_UPDATE,"pager", Array(mob+1)
           objUser.PutEx ADS_PROPERTY_UPDATE,"homephone", Array(mob+2)
           objUser.PutEx ADS_PROPERTY_UPDATE,"TelexNumber", Array(mob+1)
           WScript.Sleep 30
    I only need to fix the getobject String any help with that would be great. i need itto point to the Remote computer on which the active directory is installed.Other than this the script is working when i run it on the computer on which AD is installed
    Last edited by Ossian; 21st June 2010, 08:48. Reason: Mod added CODE tags

  • #2
    Re: vbscript to update active directory on remote computer

    any help would be great


    • #3
      Re: vbscript to update active directory on remote computer

      This must set a new site record!
      No answer in ONE minute, so the post is being bumped
      Please give people a chance to read your post and perhaps think a little bit.

      There should be no issue running an AD script from any PC, certainly with the adminpak installed and probably even without it. Why not try a simple script to connect to AD and query properties, then if your account has permission to make changes, you should be OK
      Tom Jones
      MCT, MCSE (2000:Security & 2003), MCSA:Security & Messaging, MCDBA, MCDST, MCITP(EA, EMA, SA, EDA, ES, CS), MCTS, MCP, Sec+
      PhD, MSc, FIAP, MIITT
      IT Trainer / Consultant
      Ossian Ltd

      ** Remember to give credit where credit is due and leave reputation points where appropriate **


      • #4
        Re: vbscript to update active directory on remote computer

        Well i dont have other scripts with me ,, however this script runs perfectly well on the computer on which AD is installed. How can i find out if my acount has permissions for changes ??


        • #5
          Re: vbscript to update active directory on remote computer

          then find another script ?

          you find out if your account has permissions for changing AD properties by, shock horror, attempting to change an AD property.

          AD won't care which computer a request comes from,. provided the user object that authenticates for the request has permission.
          (Of course, it may not work if the Computer Account does not belong to AD, but you already know that I guess)
          Please do show your appreciation to those who assist you by leaving Rep Point


          • #6
            Re: vbscript to update active directory on remote computer

            I'm not a scripting guru, but I can answer your question.
            The answer is - you don't need nothing to use scripting API for AD beside obvious two prerequisites:
            - Windows scripting host installed and functioning (it's there by default, can be updated to last version to prevent compatibility issues and bug fixes).
            - Read/Write permissions to the object you want to modify. You can read most objects by default. As tehcamel stated - if you don't have permissions, you'll get obvious "access denied". If you want to verify it visually, you do need AD "users and computers" snap-in, part of admin pack/RSAT for windows (depends on your client version). Open ADUC, go to "view", select "advanced features". Now go to the object in question and open it's properties. Go to the "security" tab and verify permissions. If you are not there, possibly a group you are a member of is there. If not, ask for someone with the "write" permissions to give you appropriate permission for the object in question.

            IMHO, "Dim" is used to declare variables, however it should be used with "option explicit", otherwise it has not value besides one more line of code

            MCSE 2003, MCITP EA, VCP4.