rlinux rlinux - 4 months ago 15
PowerShell Question

Search and Organize Data through windows command line

I'm a newbie in windows scripting, so bear with me.

I want to find "test" folder from multiple folders. Such as

Search test folders from multiple paths:

/rbl.com/mailroot/test
/pml.com/mailroot/test
/pax.com/mailroot/


Want to get output like that:

test@rbl.com
test@pml.com


I have run this command to get results
dir /S test > c:\results.txt


Output:

Volume in drive C has no label.
Volume Serial Number is 4A9E-06D4

Directory of C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Postoffices\rbl.com\MAILROOT

08/05/2016 12:36 AM <DIR> test
0 File(s) 0 bytes

Directory of C:\Program Files (x86)\Parallels\Plesk\Mail Servers\Mail Enable\Postoffices\pml.com\MAILROOT

08/05/2016 12:36 AM <DIR> test
0 File(s) 0 bytes


But how to extract the information like:

test@rbl.com
test@pml.com

Answer

This should do the trick

 ls test -Directory -Recurse | % { "$($_.Name)@$($_.Parent.Parent.Name)" }

It searches your folders recursively for test folders, then prints out the folder's parent it's parent, and the folder's name as you want it formatted.