0

I'm trying to get all the ERROR and WARN lines to files with the name of an object, like the following:

$items = Get-ChildItem -Path "C:\Test"

foreach ($item in $items)
{
    gci $item *.log* -rec -Force -ErrorAction SilentlyContinue |
        Select-String "WARN|ERROR" >> "C:\MyDir$item.Name_logTest.txt"
}

However, the recursive flag doesn't allow me to go over all folders.

EDIT: Guys, I figured it out. Instead of using "gci $item", I used "gci $item.PSPath"

  • Try this one http://stackoverflow.com/questions/18847145/loop-through-files-in-a-directory-using-powershell – The scion May 17 '16 at 11:22
  • Please describe us what exactly you want. Maybe provide a simple example. – Martin Brandl May 17 '16 at 11:56
  • In the code I've provided before, I want to get a file for every $item in the directory "C:Test" with the ERRORs and WARNs. The reason I want this is because the folders below the "C:Test" represent the objects I need to extract the info from. – Miguel Lobão May 17 '16 at 12:42
  • The answer was not for you Ansgar. Those ERRORs and WARNs are from a proprietary application. – Miguel Lobão May 17 '16 at 13:19

1 Answers1

0
ForEach ($Item in (Get-ChildItem -Path "C:\Test" -filter "*.log" -recurse)) {...
iRon
  • 20,463
  • 10
  • 53
  • 79