Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interactive Select from List in Powershell

Is there a plugin or tool that will let me display a list of objects to a user (Format-Table style) and allow them to use the cursor to select a choice from the list, including potentially scrolling a long list? I would like to be able to do something like this:

Get-User -anr $search |Get-Choice| Set-User -EnableAccount true

This script should display a list of matching accounts at a console prompt, allow the user to scroll up and down the list interactively, and select a choice by pressing Enter (or pass null if the user hits escape). Only one account would be passed to Set-User, rather than a list of all matching choices.

Obviously details could differ. While I would prefer a console version, a graphical one would be acceptable (that popped up a Windows dialog). The exact keystrokes could be different. But the core goal (accepting a list, getting user input, piping out the result) should be met.

like image 933
Myrddin Emrys Avatar asked May 22 '12 16:05

Myrddin Emrys


2 Answers

in v3:

Get-User -anr $search | Out-GridView -PassThru | Set-User -EnableAccount true
like image 195
walid2mi Avatar answered Nov 03 '22 00:11

walid2mi


Take a look to Out-Form

pseudo use:

out-form -title "Enable Account" -data (Get-user -anr $search) -columnNames ("AccountName") `
    -columnProperties ("SamAccountName") -actions @{Enable It!" = { $_ | Set-User -EnableAccount true}}
like image 25
CB. Avatar answered Nov 03 '22 00:11

CB.