I'm trying to look through all files in a path including any sub-folders on a network share. I'm looking for a specific string within the files. The string is set in $searchPattern and the starting directory is under $path.
I know there's at least one result that it should find and it returns nothing. The search string has to include the newline character so I included that in the variable. I'm looking for help as to why I may not be getting what I expect? I'm relatively new to PS1 scripting.
For what its worth, I think it has to do with the newline. When I remove the `n from the searchPattern variable, I do get results back... but what I'm trying to accomplish is find any records where there's no printer set and a sample of that is included below.
Thank you!
$path = '\\printershare\printers\'
$searchPattern = 'label_printer=`n'
# note the newline char at the end of the pattern
Get-ChildItem $path -recurse | Select-String -pattern $searchPattern | group path | select name
sample file that has contents I'm looking for. This file has no label printer set.
[Printers]
local_printer=printer001
local_pharm_printer=printer001
label_printer=
local_nursing_printer=printer001
hosp_pharm_printer=printer001
hosp_nursing_printer=printer001
^label_printer=$^means start of string,$means end of string.