In response to the monkut suggestion, here is a simple function to get file paths using WindowsForms OpenFileDialog :
[void] [Reflection.Assembly]::LoadWithPartialName( 'System.Windows.Forms' ) function Select-File( [string]$initialDirectory=$pwd, [switch]$multiselect ) { $dialog = New-Object Windows.Forms.OpenFileDialog $dialog.ShowHelp = $true
I also tried to create a similar Select-Directory function, but the FolderBrowserDialog STA stream requirement is pretty hard to achieve in PowerShell v1.
Edit: Thanks to Gordon , a workaround to show FolderBrowserDialog using COM:
function Select-Directory( ) { $app = New-Object -COM Shell.Application $directory = $app.BrowseForFolder( 0, "Select Directory", 0 ) $path = $directory.Self.Path if( $path ) { return $path } }
Emperor XLII
source share