running Script

This commit is contained in:
Karl-Wilfried Zimmer 2024-02-06 13:28:45 +01:00
parent 926e3ceb99
commit 05c9df3b91
2 changed files with 60 additions and 0 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
tests

59
StringFinder.ps1 Normal file
View 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"
}<##>
}