Question: Power Shell: Generify the following function, so it would accept a directory path and grouping strings as function parameters. It will recursively look for text
Power Shell:
Generify the following function, so it would accept a directory path and grouping strings as function parameters. It will recursively look for text files and create summary output in table form.
function createTable() { Set-Location C:\users\blah\lab1
$F1I = Get-Content -Path .\File1.txt | Select-String -Pattern "Info:" -AllMatches $F2I = Get-Content -Path .\File2.txt | Select-String -Pattern "Info:" -AllMatches $F3I = Get-Content -Path .\File3.txt | Select-String -Pattern "Info:" -AllMatches
$F1D = Get-Content -Path .\File1.txt | Select-String -Pattern "Debug:" -AllMatches $F2D = Get-Content -Path .\File2.txt | Select-String -Pattern "Debug:" -AllMatches $F3D = Get-Content -Path .\File3.txt | Select-String -Pattern "Debug:" -AllMatches
$F1E = Get-Content -Path .\File1.txt | Select-String -Pattern "Error:" -AllMatches $F2E = Get-Content -Path .\File2.txt | Select-String -Pattern "Error:" -AllMatches $F3E = Get-Content -Path .\File3.txt | Select-String -Pattern "Error:" -AllMatches
$output="
| Name | Info | Debug | Error |
|---|---|---|---|
| File 1 | $($F1I.Count) | $($F1D.Count) | $($F1E.Count) |
| File 2 | $($F2I.Count) | $($F2D.Count) | $($F2E.Count) |
| File 3 | $($F3I.Count) | $($F3D.Count) | $($F3E.Count) |
| Total | $($($F1I.Count) + $($F2I.Count) + $($F3I.Count)) | $($($F1D.Count) + $($F2D.Count) + $($F3D.Count)) | $($($F1E.Count) + $($F2E.Count) + $($F3E.Count)) |
Out-File -FilePath C:\users\blah\lab1\test.html -InputObject $output } createTable
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
