From 05c9df3b91745353f16b6d5b7ae0e9e2992610a5 Mon Sep 17 00:00:00 2001 From: Karl-Wilfried Zimmer Date: Tue, 6 Feb 2024 13:28:45 +0100 Subject: [PATCH] running Script --- .gitignore | 1 + StringFinder.ps1 | 59 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) create mode 100644 .gitignore create mode 100644 StringFinder.ps1 diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..2b29f27 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +tests diff --git a/StringFinder.ps1 b/StringFinder.ps1 new file mode 100644 index 0000000..8a65513 --- /dev/null +++ b/StringFinder.ps1 @@ -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" + }<##> +} \ No newline at end of file