How to get the OU the machine resides in

Discussion in 'Scripting' started by supersonic_oasis, May 13, 2008.

  1. Hi all,

    We run a windows 2003 domain with XP clients. Is there a program I can run
    from the command line that would allow me to see what OU the current machine
    resides in within AD? I know gpresult shows it, but it's kind of slow, is
    there an app that does it quicker?

    Any help is appreciated, thanks.
     
    supersonic_oasis, May 13, 2008
    #1
    1. Advertisements

  2. Thanks for the reply, it does work, but it prints out the info in the GUI.
    Is there anyway to make it so if I run it from the CMD command line it will
    just print the info in the command line?
     
    supersonic_oasis, May 13, 2008
    #2
    1. Advertisements

  3. Thanks!! You da man.

     
    supersonic_oasis, May 13, 2008
    #3
  4. supersonic_oasis

    Shay Levi Guest

    Hi,

    Try this, save it in a vbs file and double click it:

    Set objSysInfo = CreateObject("ADSystemInfo")
    strComputerName = objSysInfo.ComputerName

    Set objComputer = GetObject("LDAP://" & strComputerName)
    strOUName = objComputer.Parent

    Set objOU = GetObject(strOUName)
    Wscript.Echo objOU.distinguishedName
     
    Shay Levi, May 13, 2008
    #4
  5. supersonic_oasis

    Shay Levi Guest

    you can use cscript instead, open cmd and type:

    cscript file.vbs
     
    Shay Levi, May 13, 2008
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.