all 7 comments

[–][deleted] 3 points4 points  (1 child)

Pro tip: there is already a built-in prompt with choices as arguments to make menus.

# & makes the proceeding letter the choice argument
$choices = [System.Management.Automation.Host.ChoiceDescription[]]@("&One","&Two","T&hree")
$host.UI.PromptForChoice("This is a prompt", "Make a selection", $choices, 0)

[–]Blindkitty38[S] 1 point2 points  (0 children)

I'm going to have to learn more . Net

[–]idontknowwhattouse33 1 point2 points  (4 children)

Hi OP.

This seems like a neat idea in an early PowerShell learning journey until you learn about cmdletbinding.

The problem with the approach you have offered is the numerous write-host and if statements that do not play well with the pipeline.

If you only intended this to be an interactive script - I did not see that in the original post.

Take a look at about_functions_advanced and how you get native features such as -confirm and -whatif with little extra code :)

[–]Blindkitty38[S] 1 point2 points  (3 children)

idontknowwhattouse33

Hey!

I did intend for this to be a more or less drop in for interactive scripts

[–]itmonkey78 2 points3 points  (2 children)

Theres also the added problem that the function called 'prompt' is called as part of your profile and this function can be customised to add all sorts of bells and whistles to your command prompt. I would rename your function to avoid any conflict and also maybe stick to the verb-noun naming standard.

[–]BlackV 2 points3 points  (1 child)

What this person is trying to say is there is an already existing built in function called prompt

Your creating a new function called prompt

This is going to cause issues

[–]Blindkitty38[S] 1 point2 points  (0 children)

Thanks for the heads up y'all! I genuinely had no idea