Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need a way to script powershell select-string pattern from multiple subfolders

Status
Not open for further replies.

Dave2008

Technical User
Oct 26, 2007
7
0
0
US
In Powershell I run the following script that works fine for one folder only.
Can I run the script on one folder with multiple subfolders?
Right now I have to copy all files from each subfolder to one main folder

PS C:\main folder> Select-string "897-2" .\*xls | select -u -exp filename

shows me all the names of all the files

Using Windows 7 Pro
 
Code:
Get-ChildItem -File -Recurse | Select-string "897-2" .\*xls | select -u -exp filename

I hope that helps.

Regards,

Mark

No trees were harmed in posting this message, however a significant number of electrons were terribly inconvenienced.

Work SMARTER not HARDER.
 
Sorry it didn't work
I'm new to this. Police Documents folder has about 5 subfolders with a lot of excel files. We're a manufacturer and looking to find a pattern that would be used in different files. Thank you

PS C:\0lf\police documents> Get-ChildItem -File -Recurse | Select-string "897-2" .\*.xls | select -u -ex
Get-ChildItem : A parameter cannot be found that matches parameter name 'File'.
At line:1 char:20
+ Get-ChildItem -File <<<< -Recurse | Select-string "897-2" .\*.xls | select -u -exp filename.
+ CategoryInfo : InvalidArgument: :)) [Get-ChildItem], ParameterBindingException
+ FullyQualifiedErrorId : NamedParameterNotFound,Microsoft.PowerShell.Commands.GetChildItemCommand
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top