59 lines
1.7 KiB
PowerShell
59 lines
1.7 KiB
PowerShell
|
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"
|
||
|
}<##>
|
||
|
}
|