Created
February 10, 2025 20:01
-
-
Save steviecoaster/60cbc0685fdf1c2bdd1e99f24f13b470 to your computer and use it in GitHub Desktop.
Revisions
-
steviecoaster created this gist
Feb 10, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,39 @@ function New-UserPrompt { <# .SYNOPSIS Generate a simple user prompt .DESCRIPTION Long description .PARAMETER Options An array of choices a user can select from .EXAMPLE New-UserPrompt -Options 'Larry','Curly','Moe' #> [CmdletBinding()] Param( [Parameter()] [String[]] $Options ) end { $x = 1 foreach($o in $Options){ '{0}. {1}' -f $x,$o $x++ } [int]$prompts = $x -1 $choice = Read-Host -Prompt "Select option (1-$prompts)" if([int]$choice -gt $prompts){ throw "Invalid option. Please choose between 1 and $prompts!" } else { $Options[($choice - 1)] } } }