Skip to content

Commit

Permalink
add ps module
Browse files Browse the repository at this point in the history
  • Loading branch information
scottmckendry committed Jan 10, 2024
1 parent 8fc3930 commit 3c9b2c6
Showing 1 changed file with 58 additions and 0 deletions.
58 changes: 58 additions & 0 deletions colorscript.psm1
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function Show-ColorScript {
<#
.SYNOPSIS
Prints a random color script to the console.
.DESCRIPTION
Prints a random color script to the console. Use the -Name parameter to print a specific script. Use the -List parameter to list all available scripts.
.PARAMETER Name
The name of the script to print.
.PARAMETER List
List all available scripts.
.EXAMPLE
Show-ColorScript
Prints a random script.
.EXAMPLE
Show-ColorScript -Name "elfman"
Prints the elfman script.
.EXAMPLE
Show-ColorScript -List
Prints a list of all available scripts.
#>
param(
[Parameter(Mandatory = $false)]
[string]$Name,
[Parameter(Mandatory = $false)]
[switch]$List
)

if ($List) {
# List all scripts
$scripts = Get-ChildItem -Path "$PSScriptRoot/colorscripts" -Filter *.ps1
$scripts | ForEach-Object {
Write-Host $_.BaseName
}

return
}

if ($Name) {
# Get script by name
$script = Get-ChildItem -Path "$PSScriptRoot/colorscripts" -Filter "$Name.ps1"
if ($script) {
# Run script
& $script.FullName
} else {
Write-Error "Script '$Name' not found"
}

return
}

$scripts = Get-ChildItem -Path "$PSScriptRoot/colorscripts" -Filter *.ps1

# Get random script
$script = $scripts | Get-Random

# Run script
& $script.FullName
}

0 comments on commit 3c9b2c6

Please sign in to comment.