Wednesday, March 25, 2015

Who needs PowerShell...

Well I do... that title is supposed to be a joke, but here is an interesting line of DOS that shows just how powerful the old lady is, and how PowerShell has its roots in this old style scripting.

I needed to dump the contents of our entire DNS into a text file, of course I could have used NETSH but this was more fun:

Word-wrap aside, this is a one line command (I have munged the DNS zone names for security reasons)

for %%z in ( do @echo ls -d %%z|NSLOOKUP > out.txt

Notice the use of a DOS 'For' loop and the use of the pipe to inject commands into the NSLOOKUP executable.

(Remember double %% inside a script, single % on the command line)


No comments:

Post a Comment