Select-FromGridView – Tinkering with Powershell V3

From a 2012 SG entry – a quick and easy way to present a menu of objects to select for processing.  Uses the out-gridview -outputmode option to present a gridview of selected properties of the objects.  What is displayed in the gridview is for display purposes only.  The original objects will be returned.

function Select-FromGridView {
               Selects objects from an array using a gridview of selected properties.
              Offers a gridview to select one or more objects from a an array, 
              by a list of selected properties. Input objects will be added to an
              array, and a display object created.  The display object will have an IDX
              property that is the original object index position in the array, and the
              properties specified in the -By parameter taken from the original object.
              The display objects will appear in the gridview. After the selection is made, 
              the IDX property from the selected display object(s) will be used to select the
               original objects from the array to return - i.e. the return will be the original 
               objects, with all properties and methods intact, not the display objects. 
              $users | select-fromgridview -by * -single | unlock-adaccount
              get-childitem *.csv | select-fromgridview -by name,lastwritetime -single | invoke-item
              get-childitem *.txt |
               select-fromgridview -by name,length,creationtime -Title 'Choose files to open'|

            #Requires -Version 3


             # Objects to select from

             # Fields to display in gridview


             # Title to display on gridview

             # Select single object


             If ($Single){
                   $OutputMode = 'Single'


             Else {

                   $outputMode = 'Multi'


           If (-not $Title){

                   If ($Single){
                                 $Title = 'Choose one.'


                     Else {

                                 $Title = 'Choose one or more'



           $gridview = @{
                          Title = $Title
                          OutputMode = $OutputMode

           $IDX = 0

           $Display = @()

           $InputArray = @()

           $By = @('IDX') + $By




            $InputArray += $_
            $DisplayItem =   $_ | Select-Object $By

            $DisplayItem.IDX = $IDX++

            $Display += $DisplayItem



         $Selected = $Display | Out-Gridview @GridView
           Foreach ($Selection in $Selected){




2 responses to “Select-FromGridView – Tinkering with Powershell V3

  1. Awesome indeed, dude! I made one very small change, I added a default of “*” to the “-by” parameter. So if I did not set that parameter, it would just show all properties by default. I had to remove the mandatory and add the default, as noted here:

    # Fields to display in gridview
    $By = “*”,

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s