This script works, but I would like to add a few more things to the process, and need some help.
1) Search multiple folders 2) Search for multiple strings patterns (error,failed) 3) use a dynamic error log filename instead of hard coded in the export-csv 4) Email results.
-Path "\\ftpsrv\logs\" | `
Select-String -pattern "failed" | `
Select-Object -Property Path,LineNumber,Line | `
Export-CSV "C:\ftp_in\archive\errors.csv" -Append
I'm don't know enough about PowerShell to write code in it and so I can't actually help here.
If you have a moment, I AM curious, though. What is this code doing?
My guess is that you're identified a UNC to a share, are doing the equivalent of a filtered DIR looking for file names that have the word "failed" somewhere in the file name, and then writing the path and a couple of other things out a CSV on some local system that you're running all of this from.
What does "LineNumber" contain? Is that just some sequential line number created by ChildItem? And, what is in Line? Is that where the filename is actually present and, if so, is there other data that is also available in the Line?
Last but not least, you're saving whatever it is that's being built (would love to see a few lines from the CSV), you're appending it to an existing CSV. What do you intend to do with the contents of that CSV?
Like I said, I can't actually help here but I'd like to know much more about the problem that you're trying to solve so I can do a little research on how one might solve the problem in PoSh and also understand why you need to do this and store it in a CSV to begin with.