Announcement

Collapse
No announcement yet.

Ldap

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Ldap

    Hi

    I'm trying to get the attributes from the sub trees of an AD container. Is there a way that you could pass a CN from a txt file as a variable. Here is my code so far:

    DIM fso, TxtFile

    Set fso = CreateObject("Scripting.FileSystemObject")
    Set TxtFile = fso.CreateTextFile("EA-Computers.txt", True)

    'Enumerate Computer GUID's
    Set objOU = GetObject("LDAP://mtb0120vledepii:389/ou=EncryptionAnywhereComputers,dc=ede,dc=irs,dc=go v")
    For Each objUser in objOU

    TxtFile.WriteLine (ObjUser.Name)
    Next
    TxtFile.Close

    'open the file system object
    Set oFSO = CreateObject("Scripting.FileSystemObject")
    set WSHShell = wscript.createObject("wscript.shell")
    'open the data file
    Set oTextStream = oFSO.OpenTextFile("EA-Computers.txt")
    'make an array from the data file
    RemotePC = Split(oTextStream.ReadAll, vbNewLine)
    'close the data file
    oTextStream.Close



    For Each strComputer In RemotePC
    'Do something useful with strComputer here

    Set obj = GetObject("LDAP://mtb0120vledepii:389/OU=EncryptionAnywhereComputers,DC=EDE,DC=irs,DC=go v")

    Wscript.Echo obj.Get("ea-ComputerName")


    Next

    I need the variable to be plugged in before

    OU=EncryptionAnywhereComputers,DC=EDE,DC=irs,DC=go v")

    I've tried this but no luck:

    dim CN
    CN = strcomputer

  • #2
    Re: Ldap

    It should have been posted under "Scripting" section.

    Regards,
    Kapil Sharma
    ~~~~~~~~~~~~~
    Life is too short, Enjoy It.

    Comment


    • #3
      Re: Ldap

      See the below example to move the computers listed in ADdump.txt fiel:

      ************************************************** **************
      on error resume next
      Const Formyfile = 1
      Const ADS_SCOPE_SUBTREE = 2
      Set con = CreateObject("ADODB.Connection")
      Set com = CreateObject("ADODB.Command")
      Set rsset = CreateObject("ADODB.recordset")
      con.Provider = "ADsDSOObject"
      con.Open "Active Directory Provider"
      com.ActiveConnection = con
      com.Properties("searchscope") = 2
      com.Properties("Page Size") = 100000
      com.Properties("Searchscope") = ADS_SCOPE_SUBTREE
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set ts = fso.OpenTextFile("D:\Script\MoveComputers\ADdump.t xt",formyfile,True)
      Set objOU = GetObject("LDAP://OU=xyz,DC=abc,DC=com")

      do While Not ts.AtEndOfStream
      strCompsID = Trim(ts.ReadLine)

      strQuery = "<LDAP://dc=abc,dc=com>;(&(objectclass=computer)(cn=" & strCompsID & "));ADsPath"
      Com.CommandText = strQuery
      Set rsset = com.Execute

      strADsPath = rsset.Fields("ADsPath").value
      objOU.MoveHere strADsPath, vbNullString

      loop
      ************************************************** ***************

      Regards,
      Kapil Sharma
      ~~~~~~~~~~~~~
      Life is too short, Enjoy It.

      Comment

      Working...
      X