Home > Back-end >  Get-ChildItem into Powershell ListBox GUI
Get-ChildItem into Powershell ListBox GUI

Time:02-24

I am trying to find out how I can put the output of an Get-ChildItem into a ListBox.

My idea is, that I want to list the contents of one folder as an Drop-Down Menu within a small Powershell Window. The function then should run the selected file with predefined parameters.

Do you have any idea how to accomplish that?

I tried setting the values of Get-ChildItem as a variable, but then all I get is everything in one line and as one single option.

Thanks in advance!

CodePudding user response:

You can use Out-GridView to show the files in a popup dialog which lets you select a file and return the selection.

$selectedFile = Get-ChildItem | Out-GridView -Title 'Select a file' -OutputMode Single

Write-Host "Selected file: $($selectedFile.Name)"

Use Select-Object to change which columns are shown by Out-GridView:

$selectedFile = Get-ChildItem | Select-Object Name, LastWriteTime | Out-GridView -Title 'Select a file' -OutputMode Single

Write-Host "Selected file: $($selectedFile.Name)"
  • Related