Functions/FileSystem/Select-OpenFilePath.ps1
function Select-OpenFilePath { PARAM ( [Parameter(Mandatory=$false)] [string] $StartPath = "C:\", [Parameter(Mandatory=$false)] [string] $Description = "Select a File" ) [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null [System.Windows.Forms.Application]::EnableVisualStyles() $browse = New-Object System.Windows.Forms.OpenFiledialog $browse.initialdirectory = $Startpath $browse.title = $Description $loop = $true while($loop) { if ($browse.ShowDialog() -eq "OK") { $loop = $false } else { $res = [System.Windows.Forms.MessageBox]::Show("You clicked Cancel. Would you like to try again or exit?", "Select a location", [System.Windows.Forms.MessageBoxButtons]::RetryCancel) if($res -eq "Cancel") { return } } } $browse.filename $browse.Dispose() } |