Functions/FileSystem/Find-FolderPath.ps1
function Find-FolderPath { PARAM ( [Parameter(Mandatory=$false)] [string] $StartPath = "C:\", [Parameter(Mandatory=$false)] [string] $Description = "Select a Folder" ) [Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") | Out-Null [System.Windows.Forms.Application]::EnableVisualStyles() $browse = New-Object System.Windows.Forms.FolderBrowserDialog $browse.RootFolder = "MyComputer" $browse.Description = $Description $browse.ShowNewFolderButton = $true $loop = $true while($loop) { if ($browse.ShowDialog((New-Object System.Windows.Forms.Form -Property @{TopMost = $true})) -eq "OK") { $loop = $false } else { $res = [System.Windows.Forms.MessageBox]::Show($this, "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.SelectedPath $browse.Dispose() } |