Solved

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

Posted on 2011-09-19
4
324 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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

This article is the result of a quest to better understand Task Scheduler 2.0 and all the newer objects available in vbscript in this version over  the limited options we had scripting in Task Scheduler 1.0.  As I started my journey of knowledge I f…
If you get continual lockouts after changing your Active Directory password, there are several possible reasons.  Two of the most common are using other devices to access your email and stored passwords in the credential manager of windows.
Notifications on Experts Exchange help you keep track of your activity and updates in one place. Watch this video to learn how to use them on the site to quickly access the content that matters to you.
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…

707 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

18 Experts available now in Live!

Get 1:1 Help Now