chelnak
3/27/2015 - 1:12 PM

Search for a string in multiple files

Search for a string in multiple files

#Needed to search for invalid hostname inside lots of config files

$wrongHost = "the-host.com"
$path = "D:\Program Files (x86)\VMware\vCAC\"

Get-ChildItem -Path $path -Filter *.config -Recurse | ? { !$_.PSIsContainer } | % {
  
  $f = Get-Content $_.FullName
  $c = $f | % { $_ -match $wrongHost }
  
  if ($c -contains $true)
  {
    Write-Host $_.FullName
  }

}