I have a problem. I'm going to search files on my computer for keywords in the files. The keyword is for example "C:\Project". I get error when running this script below. But when i'm deleting C:\ in the search string it's working. But i'm interested in to search with C:\ in the beginning. Can someone help me with correction in the script?
$path = 'D:\Cross'
$searchword = 'C:\Project'
$Filename = '*.config'
Get-ChildItem $path -Include "$Filename" -Recurse | ForEach-Object {
If (Get-Content $_.FullName | Select-String -Pattern $searchword ){
$PathArray += $_.FullName
}
}
Write-Host "Contents of ArrayPath:"
$PathArray | ForEach-Object {$_}