Find all the OU path of computers and Usernames

Posted on 2007-08-07
Last Modified: 2008-01-09

I have a file which has some computers and user NT logins.I want to find the OU path of all these machines.Is there a way to find this.

Question by:bsharath
    LVL 12

    Expert Comment

    "How to find which OU a computer is in"

    LVL 26

    Accepted Solution

    :: ===============
    :: ===============
    :: * This script SAMIDs.txt file on C: drive root, from where it will SAM ID's of users and computers.
    :: * Successful run will generate "OUPath.txt" file on C: drive root.
    :: * Copy and paste following script in notepad and save it with any name having .cmd extension.
    :: *** SCRIPT START ***
    @Echo Off
    SETLOCAL EnableDelayedExpansion

    IF NOT EXIST C:\SAMIDs.txt Goto ShowErr
    FOR %%R IN (C:\SAMIDs.txt) Do IF %%~zR EQU 0 Goto ShowErr
    IF EXIST C:\OUPath.txt DEL /F /Q C:\OUPath.txt

    FOR /F "delims=#" %%a IN ('Type C:\SAMIDs.txt') Do (
        Echo Processing: %%a
          SET Qry=DSQuery * DomainRoot -Filter "(&(objectClass=User)(sAMAccountName=%%a*))" -Attr distinguishedName -L ^| Find "CN="
          FOR /F "delims=, tokens=2*" %%x IN ('!Qry!') Do Echo %%a : %%x %%y >>C:\OUPath.txt
    Goto EndScript
    Echo 'C:\SAMIDs.txt' file does not exist or file is empty!
    :: *** SCRIPT END ***

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    The way I use Experts Exchange to assist me in analyzing and diagnosing a problem is I first enter a Verbose Question at Experts Exchange like: Office 2007 will hang when opening and saving files I then launch WordPad (any text editor will do) an…
    Welcome to my series of short tips on migrations. Whilst based on Microsoft migrations the same principles can be applied to any type of migration. My first tip is around source server preparation. No migration is an easy migration, there is a…
    This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    754 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    14 Experts available now in Live!

    Get 1:1 Help Now