[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Find all the OU path of computers and Usernames

Posted on 2007-08-07
2
Medium Priority
?
1,512 Views
Last Modified: 2008-01-09
Hi,

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.

Regards
Sharath
0
Comment
Question by:bsharath
2 Comments
 
LVL 12

Expert Comment

by:zoofan
ID: 19645320
"How to find which OU a computer is in"

http://www.tek-tips.com/viewthread.cfm?qid=1098379&page=2


zf
0
 
LVL 26

Accepted Solution

by:
Farhan Kazi earned 2000 total points
ID: 19647854
:: ===============
:: READ THIS FIRST
:: ===============
:: * 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
:ShowErr
Echo 'C:\SAMIDs.txt' file does not exist or file is empty!
:EndScript
ENDLOCAL
:: *** SCRIPT END ***
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is my 3rd article on SCCM in recent weeks, the 1st (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/Windows_Server_2008/A_4466-A-beginners-guide-to-installing-SCCM2007-on-Windows-2008-R2-Server.html) dealing with installat…
INTRODUCTION The purpose of this document is to demonstrate the Installation and configuration of the Data Protection Manager product. Note that this demonstration was prepared on the basis of Windows OS is 2008 R2 and DPM 2010. DATA PROTECTI…
Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
Windows 8 came with a dramatically different user interface known as Metro. Notably missing from that interface was a Start button and Start Menu. Microsoft responded to negative user feedback of the Metro interface, bringing back the Start button a…
Suggested Courses

872 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