Jump to content

Active Directory Query


Recommended Posts

I am working on a script that will do an automated install on all the computers on the Domain that meet specific criteria. In this case, I only want the script to run if the computer exists in a specific group. For instance, if the Computer exists in the Laptops group, run the script. Otherwise, exit.

whowd has a great post at http://www.autoitscript.com/forum/index.ph...hl=Truman+State that queries the Active Directory and sets the focus on the OU that the current computer is a member of, so I know it can be done, I just don't have any idea how to do it.

Thanks in advance for your help! :D

Link to comment
Share on other sites

Hey, I think I got it! I edited whowd's script to remove all the GUI stuff, and then changed the following section:

$computersCN = returnObjectDN($computername, "computer")
If $computersCN <> "0" Then
    $computersOU = returnFullOUfromDN($computersCN) 
    UpdateProgressText("Found this computer (" & $computername & ") in the " & _
                returnFriendlyName($computersOU) & " OU - This has been selected " & _
                "for you below.")
    GuiCtrlSetState(_ArraySearch($treeIDArray, $computersOU), $GUI_FOCUS)
EndIf

to:

$computersCN = returnObjectDN($computername, "computer")
If $computersCN <> "0" Then
    $computersOU = returnFullOUfromDN($computersCN)                 
EndIf

If $computersOU = "OU=Desktops,OU=Computers,OU=NMC,DC=DOMAIN,DC=COM" Then 
    Call("InstallUltraVNC")
ElseIf $computersOU = "OU=Laptops,OU=Computers,OU=NMC,DC=DOMAIN,DC=COM" Then 
    Call("InstallUltraVNC")
ElseIf $computersOU = "OU=Computers,OU=RCC,DC=DOMAIN,DC=COM" Then 
    Call("InstallUltraVNC")
Else
    Exit
EndIf

(Obviously with DC=DOMAIN,DC=COM replaced with the correct domain info.) Works beautifully! There may very well be a simpler way to do it, but this works for now.

So, thanks to whowd for helping me with the solution to my problem! :D

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...