call FolderBrowserDialog from powershell call FolderBrowserDialog from powershell powershell powershell

call FolderBrowserDialog from powershell


I encountered this problem a while back and found the following COM workaround on the MSDN forums:

$app = new-object -com Shell.Application$folder = $app.BrowseForFolder(0, "Select Folder", 0, "C:\")if ($folder.Self.Path -ne "") {write-host "You selected " $folder.Self.Path}

http://www.microsoft.com/communities/newsgroups/en-us/default.aspx?dg=microsoft.public.dotnet.framework.windowsforms.controls&tid=3607557a-43b3-40bf-8276-be00526e0520&p=1


I believe it is a problem with PowerShell running in a MTA Thread. You can run the CTP of Version 2 in a STA (single threaded apartment) mode and it will pull up the proper folder selection. It does pull the menu up behind the shell window though.


Just FYI, if you are looking to do Windows Forms stuff, there is one product currently out that will do windows forms for PowerShell (The Admin Script Editor) and Sapien is working on a Forms Designer (announced on the PowerScripting Podcast), which might smooth out some of these issues for your script.