running Script
This commit is contained in:
parent
926e3ceb99
commit
05c9df3b91
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
tests
|
59
StringFinder.ps1
Normal file
59
StringFinder.ps1
Normal file
@ -0,0 +1,59 @@
|
||||
function Get-PathItems {
|
||||
param (
|
||||
[string]$Path
|
||||
)
|
||||
if (Test-Path -Path $Path -PathType Container) {
|
||||
return Get-ChildItem -Path $Path -Recurse -Force -Attributes !Directory #Directories can't be scanned by Select-String so don't show them in listing
|
||||
}
|
||||
throw "Virable path $($Path) must be a Folder or Container."
|
||||
}
|
||||
|
||||
function Get-Lines {
|
||||
param (
|
||||
[string]$StingFilePath
|
||||
)
|
||||
if ((Test-Path -Path $StingFilePath -PathType Leaf)){
|
||||
$item = Get-Item -Path $StingFilePath
|
||||
$ext = $item.Extension
|
||||
if($ext -like "*.txt"){
|
||||
return Get-Content -Path $StingFilePath
|
||||
}
|
||||
}
|
||||
throw "Variable StringFilePath $($StringFilePath) must be a txt file"
|
||||
}
|
||||
|
||||
function Check-Files {
|
||||
param (
|
||||
[string]$Path,
|
||||
[string]$StingFilePath
|
||||
)
|
||||
$Items = Get-PathItems -Path $Path
|
||||
$Lines = Get-Lines -StingFilePath $StingFilePath
|
||||
Write-Host "Items Found $($Items.Count)"
|
||||
Write-Host $Lines.Count
|
||||
<#$Items | Foreach-Object -ThrottleLimit 5 -Parallel {
|
||||
#"starting on $_"
|
||||
foreach ($line in $Lines){
|
||||
try {
|
||||
Select-String -Path $_ -Pattern $line
|
||||
}
|
||||
catch {
|
||||
Write-Host "$_ couldn't be processed by Select-String"
|
||||
}
|
||||
}
|
||||
#"ended $_"
|
||||
}#>
|
||||
|
||||
<##>foreach($item in $Items){
|
||||
#Write-Host "starting on $item"
|
||||
foreach ($line in $Lines){
|
||||
try {
|
||||
Select-String -Path $item -Pattern $line | Select-Object -Property Path,LineNumber | Format-Table -AutoSize
|
||||
}
|
||||
catch {
|
||||
Write-Host "$item couldn't be processed by Select-String"
|
||||
}
|
||||
}
|
||||
#Write-Host "ended $item"
|
||||
}<##>
|
||||
}
|
Loading…
Reference in New Issue
Block a user