mirror of
https://github.com/fleschutz/PowerShell.git
synced 2024-11-14 03:54:46 +01:00
Improved search-files.ps1
This commit is contained in:
parent
9f7552b386
commit
bad24e40ac
@ -8,7 +8,17 @@
|
||||
|
||||
param([string]$Pattern = "", [string]$Path = "")
|
||||
|
||||
Set-StrictMode -Version Latest
|
||||
function ListScripts { param([string]$Pattern, [string]$Path)
|
||||
$List = Select-String -Path $Path -Pattern "$Pattern"
|
||||
foreach ($Item in $List) {
|
||||
New-Object PSObject -Property @{
|
||||
'Path' = "$($Item.Path)"
|
||||
'Line' = "$($Item.LineNumber)"
|
||||
'Text' = "$($Item.Line)"
|
||||
}
|
||||
}
|
||||
write-output "(pattern found at $($List.Count) locations)"
|
||||
}
|
||||
|
||||
try {
|
||||
if ($Pattern -eq "" ) {
|
||||
@ -18,10 +28,7 @@ try {
|
||||
$Path = read-host "Enter path to files"
|
||||
}
|
||||
|
||||
$List = Select-String -Path $Path -Pattern "$Pattern"
|
||||
foreach ($Item in $List) {
|
||||
write-output "$($Item.Path) @$($Item.LineNumber)`t$($Item.Line)"
|
||||
}
|
||||
ListScripts $Pattern $Path | format-table -property Path,Line,Text
|
||||
exit 0
|
||||
} catch {
|
||||
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
|
||||
|
Loading…
Reference in New Issue
Block a user