Solved

Script to find specific words in a text file and export them to another

Posted on 2011-09-19
4
334 Views
Last Modified: 2012-05-12
Hey guys,

I have exported all my computer names in a certain OU to a txt file using dsquery

Unforntunately it exports the computer names along with the CNs and all that good stuff
"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"

I need to find a way to extract the computername to another txt which they all start with mtlwksxxxx or mtllapxxxx where x is a set of 4 variable digits ,

So in the new txt file i just want the computer names to show

Thanks!
0
Comment
Question by:WBGames
4 Comments
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 36562549
Would extracting the information in the format you require by easier?

dsquery computer "ou=whatever,dc=domain,dc=com" -scope onelevel -name mtl* -o rdn > pclist.txt

-o rdn will extract just the relative dn.

Steve
0
 
LVL 7

Expert Comment

by:ednetman
ID: 36562560
What command are you running in dsquery?  I think there is an option to show only the hostname, as opposed to the full OU structure.
0
 
LVL 37

Expert Comment

by:Gerwin Jansen
ID: 36563106
When text.txt is your txt file containing:

"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLWKSxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLLAPxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"
"CN=MTLSRVxxxx,OU=xxxx,OU=xxxxx,OU=xxxx,DC=xxxx,DC=com"

This would extract your system names:

for /f "tokens=2 delims==," %f in (test.txt) do @echo %f | findstr "MTLWKS MTLLAP"

Open in new window


Output:

MTLWKSxxxx
MTLWKSxxxx
MTLLAPxxxx
0
 
LVL 1

Author Closing Comment

by:WBGames
ID: 36563113
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Learn more about the importance of email disclaimers with our top 10 email disclaimer DOs and DON’Ts.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
The Bounty Board allows you to request an article or video on any technical topic, or fulfill a bounty request to earn points. Watch this video to learn how to use the Bounty Board to get the content you want, earn points, and browse submitted bount…
Saved searches can save you time by quickly referencing commonly searched terms on any topic. Whether you are looking for questions you can answer or hoping to learn about a specific issue, a saved search can help you get the most out of your time o…

943 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

11 Experts available now in Live!

Get 1:1 Help Now