Improved list-scripts.ps1

This commit is contained in:
Markus Fleschutz 2021-01-02 11:16:16 +00:00
parent e2f8513719
commit 80ca148f65
2 changed files with 14 additions and 12 deletions

View File

@ -12,10 +12,8 @@ function ListDirectory { param([string]$Path)
$Items = get-childItem -path $Path $Items = get-childItem -path $Path
foreach ($Item in $Items) { foreach ($Item in $Items) {
if ($Item.Mode -eq "d-----") { if ($Item.Mode -eq "d-----") {
#write-output "$($Item.name)/"
New-Object PSObject -Property @{ Filename = "$($Item.Name)/" } New-Object PSObject -Property @{ Filename = "$($Item.Name)/" }
} else { } else {
#write-output "$($Item.name)"
New-Object PSObject -Property @{ Filename = "$($Item.Name)" } New-Object PSObject -Property @{ Filename = "$($Item.Name)" }
} }
} }

View File

@ -6,18 +6,22 @@
.NOTES Author: Markus Fleschutz / License: CC0 .NOTES Author: Markus Fleschutz / License: CC0
#> #>
$PathToRepo = "$PSScriptRoot/.." function ListScripts { param([string]$Path)
write-progress "Reading $Path..."
$Table = import-csv "$Path"
foreach($Row in $Table) {
New-Object PSObject -Property @{
'Script' = "$($Row.Filename)"
'Description' = "$($Row.Description)"
}
}
write-output ""
write-output "($($Table.Count) PowerShell scripts total)"
}
try { try {
write-progress "Reading Data/scripts.csv..." $PathToRepo = "$PSScriptRoot/.."
$Table = import-csv "$PathToRepo/Data/scripts.csv" ListScripts "$PathToRepo/Data/scripts.csv" | format-table -property Script, Description
write-output ""
write-output "Collection of $($Table.Count) PowerShell Scripts"
write-output "==================================="
foreach($Row in $Table) {
write-output "* $($Row.Filename) - $($Row.Description)"
}
exit 0 exit 0
} catch { } catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])" write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"