PowerShell/scripts/list-scripts.ps1

52 lines
1.5 KiB
PowerShell
Raw Normal View History

2023-10-31 12:33:36 +01:00
<#
2021-07-13 21:10:02 +02:00
.SYNOPSIS
2023-09-28 13:50:01 +02:00
Lists the PowerShell scripts
2021-07-13 21:10:02 +02:00
.DESCRIPTION
2023-09-28 13:50:01 +02:00
This PowerShell script lists the Mega collection of PowerShell scripts (sorted alphabetically and optionally by category).
.PARAM category
Specifies the desired category: audio, desktop, filesystem, fun, git, misc, or: * (default)
2021-07-13 21:10:02 +02:00
.EXAMPLE
2023-08-06 21:35:36 +02:00
PS> ./list-scripts.ps1
2023-09-28 13:50:01 +02:00
No Script Category Description
-- ------ -------- -----------
1 add-firewall-rules.ps1 misc Adds firewall rules for executables (needs admin rights)
...
2021-07-13 21:10:02 +02:00
.LINK
https://github.com/fleschutz/PowerShell
2022-01-29 12:47:46 +01:00
.NOTES
2022-09-06 21:42:04 +02:00
Author: Markus Fleschutz | License: CC0
2020-12-29 15:37:12 +01:00
#>
2023-09-28 13:50:01 +02:00
param([string]$category = "*")
function ListScripts([string]$category) {
2023-10-31 11:25:11 +01:00
Write-Progress "Loading data from ../data/script.csv..."
$table = Import-CSV "$PSScriptRoot/../data/scripts.csv"
[int]$No = 1
foreach($row in $table) {
2023-09-28 13:50:01 +02:00
if ($row.CATEGORY -like $category) {
New-Object PSObject -Property @{
'No' = $No++
'Script' = $row.SCRIPT
'Category' = $row.CATEGORY
'Description' = $row.DESCRIPTION
}
2021-01-02 12:16:16 +01:00
}
2020-12-29 15:37:12 +01:00
}
2023-09-28 13:50:01 +02:00
Write-Progress -completed " "
2021-01-02 12:16:16 +01:00
}
try {
2023-09-28 13:50:01 +02:00
ListScripts $category | Format-Table -property No,Script,Category,Description
2023-09-18 18:48:56 +02:00
# $files = Get-ChildItem -path "./*.ps1" -attributes !Directory
# foreach ($file in $files) {
# $help = Get-Help $file -full
2023-09-28 13:50:01 +02:00
# Write-Output "$($file.Name), ,`"$($help.Synopsis)`","
2023-09-18 18:48:56 +02:00
# }
2021-09-27 10:09:45 +02:00
exit 0 # success
2020-12-29 15:37:12 +01:00
} catch {
2022-04-13 12:06:32 +02:00
"⚠️ Error in line $($_.InvocationInfo.ScriptLineNumber): $($Error[0])"
2020-12-29 15:37:12 +01:00
exit 1
}