Search code examples
powershelluser-interfaceprompt

Is there a Module or Something Similar for Interactive Prompts in PowerShell?


Is there something we can use in PowerShell to ask users to select one item from an array of items? For example, I like how Inquirer.js can do it.

enter image description here

I have also seen PoshGui, but it seems too much work to create just a simple prompt.

The reason we want something similar is that we need to provide deployment scripts for our clients and make deployment guides as easy as possible. Asking users to select one item on a screen is much better than asking them to insert some guid to a config file.

Do you have any suggestions for user prompts for arrays?


Solution

  • All of the answers are correct, but I also wrote a few reusable PowerShell helper functions. Readme. I auto-generate basic looking WinForms. Looks ugly, but works.

    https://github.com/Zerg00s/powershell-forms

    $selectedItem = Get-FormArrayItem (Get-ChildItem)
    

    enter image description here

    $Delete = Get-FormBinaryAnswer "Delete file?"
    

    enter image description here

    $newFileName = Get-FormStringInput "Enter new file name" -defaultValue "My new file"
    

    enter image description here

    # -------------------------------------------------------------------------------
    # Prepare the list of inputs that user needs to populate using an interactive form    
    # -------------------------------------------------------------------------------
    $preDeployInputs = @{
        suffix                       = ""
        SPSiteUrl                    = "https://ENTER_SHAREPOINT_SITE.sharepoint.com"
        TimeZone                     = "Central Standard Time"
        sendGridRegistrationEmail    = "ENTER_VALID_EMAIL_ADDRESS"
        sendGridRegistrationPassword = $sendGridPassword
        sendGridRegistrationCompany  = "Contoso & Tailspin"
        sendGridRegistrationWebsite  = "https://www.company.com"
        fromEmail                    = "[email protected]"
    }
    
    $preDeployInputs = Get-FormItemProperties -item $preDeployInputs -dialogTitle "Fill these required fields"
    

    enter image description here