Created
August 20, 2014 10:41
-
-
Save Newlifer/6cc075ee86047cd8675e to your computer and use it in GitHub Desktop.
Searches substring in the files in specific directory, recursively.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
param( | |
$place = $PSScriptRoot, | |
$what | |
) | |
$time1 = Get-Date -format HH:mm:ss | |
[array]$list = Get-ChildItem $place -recurse | %{ Write-Host Examining file: $_.fullname; $_ } | ? { $_.psiscontainer -eq $false } | ?{ gc $_.pspath | select-string -pattern $what } | %{ $_.FullName } | |
$time2 = Get-Date -format HH:mm:ss | |
$TimeDiff = New-TimeSpan $time1 $time2 | |
if( $TimeDiff.Seconds -lt 0 ) { | |
$Hrs = ( $TimeDiff.Hours ) + 23 | |
$Mins = ( $TimeDiff.Minutes ) + 59 | |
$Secs = ( $TimeDiff.Seconds ) + 59 | |
} | |
else { | |
$Hrs = $TimeDiff.Hours | |
$Mins = $TimeDiff.Minutes | |
$Secs = $TimeDiff.Seconds | |
} | |
$Difference = '{0:00}:{1:00}:{2:00}' -f $Hrs, $Mins, $Secs | |
Write-Host "Time elapsed: " $Difference | |
Write-Host "Files found: " $list.Length | |
foreach( $file in $list ) { | |
Write-Host $file | |
} | |
Write-Host "Done!" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment