Monday, December 5, 2011

powershell script to scan all files in a folder (and subfolders) and get string containing

$dir = "d:\test"
$filename = "*.txt"
$temp=Get-ChildItem -Recurse $dir | Where-Object {$_.Name -like $filename} | Select-Object -Property Fullname, Name
"Starting File " | Out-File "c:\test.txt"
" "
foreach($tmp in $temp)
{
$tmp.Name.SubString(0,5) | Out-File "c:\test.txt" -append
get-content -path $tmp.FullName | Select-string "interface | ip address " | Out-File "c:\test.txt" -append
}