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
foreach ($Item in $Items) {
if ($Item.Mode -eq "d-----") {
#write-output "$($Item.name)/"
New-Object PSObject -Property @{ Filename = "$($Item.Name)/" }
} else {
#write-output "$($Item.name)"
New-Object PSObject -Property @{ Filename = "$($Item.Name)" }
}
}

View File

@ -6,18 +6,22 @@
.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 {
write-progress "Reading Data/scripts.csv..."
$Table = import-csv "$PathToRepo/Data/scripts.csv"
write-output ""
write-output "Collection of $($Table.Count) PowerShell Scripts"
write-output "==================================="
foreach($Row in $Table) {
write-output "* $($Row.Filename) - $($Row.Description)"
}
$PathToRepo = "$PSScriptRoot/.."
ListScripts "$PathToRepo/Data/scripts.csv" | format-table -property Script, Description
exit 0
} catch {
write-error "ERROR in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"