Skip to content

Instantly share code, notes, and snippets.

@chelnak
Created March 27, 2015 13:12
Show Gist options
  • Select an option

  • Save chelnak/63134529862128a35cec to your computer and use it in GitHub Desktop.

Select an option

Save chelnak/63134529862128a35cec to your computer and use it in GitHub Desktop.
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
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment