PeetersOnline.nl
Powershell Open File Dialog Box
Do you ever require the users of your script to select which file to use?
I do. And it’s no fun trying to do decent error-handling when a user has to type the full path to a file. Nor is it any fun to be that user. So why not use the Windows Forms class of .Net to show the Open File Dialog Box?
Select-FileDialog function (rename to .ps1 or copy into your profile)
User happy. Me happy. You happy?
No related posts.
12 Responses to Powershell Open File Dialog Box
Tags
Active Directory API bind order cleanup cluster CPU Custom Fields datastores description device management directory tree errors Event Log file name filter Fun function HA IT known issues License Server LUN multipath NIC objects Oneliner portgroups PowerCLI PowerShell profile recursive Registry Scripts security session share snapshots SQL Stat VI Toolkit VMware vSphere WMI WSUS ZenArchives
- July 2012
- July 2011
- February 2011
- January 2011
- December 2010
- May 2010
- October 2009
- September 2009
- August 2009
- July 2009
- June 2009
- May 2009
- April 2009
- March 2009
- February 2009
- January 2009
- December 2008
- November 2008
- October 2008
- September 2008
- August 2008
- July 2008
- June 2008
- May 2008
- April 2008
- March 2008





I’m happy
Very good example on how to use winforms.
I referenced you on my blog for getting started with PS/toolkit.
Again thanks for a nice blog!
The function hangs at this point.
$Show = $objForm.ShowDialog()
But the Dialogbox does not appear
I think i’m missing samething.
I think there is a mistake in your Example use for the filter. You have
-Filter “Powershell Scripts|(*.ps1)”
I think is should be
-Filter “Powershell Scripts (*.ps1)|*.ps1″
I made that change and then was able to see files
»crosslinked«
There seems to be a problem with powershell hanging when using the showdialog method of the openfiledialog object… There seems to be a solution to this however which is to set the ShowHelp property to $true. The default is $false, and for some reason if it is set to $false powershell will hang.
[...] geringem Aufwand erstellen. Ein schönes Beispiel für einen entsprechenden Dialog habe ich unter http://www.peetersonline.nl/index.php/powershell/powershell-open-file-dialog-box/ [...]
Thanks for posting this. Very helpful! Just had to make the correction that Jamey pointed out and it worked great!
Thanks, worked for me too, appears to hang, but check the file/dialogue box hasnt appeared behind something else on screen! Anyone know how to alter this to allow selection of file Paths rather than specific files?
Jamey Westmoreland is right. I had to modify the -Filter to see the desired files
[...] used to display a Windows open dialog box – this was based on code borrowed from Hugo Peeters http://www.peetersonline.nl/index.php/powershell/powershell-open-file-dialog-box/ – whom I send my thanks to for writing an excellent [...]
[...] Standaard denk ik dat er zoiets niet in powershell zit. Maar even googlen en ik kwam uit op deze link: Powershell Open File Dialog Box | PeetersOnline [...]
Quite useful, though when I use it with the PowerShell ISE, it puts the file dialog window behind the ISE.
Here’s a tip: You can have multiple file catagories using arguments similar to:
-Filter “Text files (*.txt)|*.txt|All files (*.*)|*.*”
i am happy!