Using Powershell in a menu

Has anyone assembled i.e. a dozen PowerShell scripts, loaded as a Function that when run, generates a Menu of all of those scripts that can then be run by the engineer?

  • Run the Function
  • The menu pops up
  • Choose an item
  • PS code runs
  • generates a log of results
  • Menu pops back with list
  • 0 - to exit

And what if the answer is “yes”? :wink:

I assume you want to have the choice to run one of the scripts - not all of them, right? You could create an index for all scripts, output the list of scripts along with their index and prompt for the index of the script to run.

See the function Write-TextMenu from my module PoshFunctions on PowerShellGallery.com. You can pass an array of options to be in the menu and it will spit out the code that is the menu.

2 Likes

Thank you I have downloaded that and will have look and test

yep, one at a time. Would have a directory of about 10 scripts for a daily health check for on-call engineer

I imported via Install-Module -Name PoshFunctions

…but when I attempt:

PS C:\> PoshFunctions

PoshFunctions : The term 'PoshFunctions' is not recognized as the name of a cmdlet,

I see that error

PoshFuntions is the name of the module - not a cmdlet. You should run “Get-Command -Module PoshFunctions” to get a list of the cmdlets available in this module

2 Likes

https://cadayton.keybase.pub/PSGallery/Modules/BOTtum/BOTtum.html
This module has a cmdlet named, Show-KBFileSystem that load and execute any powershell script. This could be adapted to do what you are looking to do.

In my prior post I mentioned to look at the function Write-TextMenu. That function is the one in the module that is most appropriate to what you asked about.