Created
May 27, 2021 12:50
-
-
Save FriedrichWeinmann/c75570c5489a39f38dae3ee7d175f6db to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Show-OpenFileDialog { | |
<# | |
.SYNOPSIS | |
Show an Open File dialog using WinForms. | |
.DESCRIPTION | |
Show an Open File dialog using WinForms. | |
.PARAMETER InitialDirectory | |
The initial directory from which the user gets to pick a file. | |
Defaults to the current path. | |
.PARAMETER Title | |
The window title to display. | |
.PARAMETER MultiSelect | |
Whether the user may pick more than one file. | |
.EXAMPLE | |
PS C:\> Show-OpenFileDialog | |
Opens a file selection dialog in the current folder | |
#> | |
[OutputType([string])] | |
[CmdletBinding()] | |
param ( | |
[string] | |
$InitialDirectory = '.', | |
[string] | |
$Title, | |
[switch] | |
$MultiSelect | |
) | |
process { | |
$dialog = [System.Windows.Forms.OpenFileDialog]::new() | |
$dialog.InitialDirectory = Resolve-Path -Path $InitialDirectory | |
$dialog.MultiSelect = $MultiSelect.ToBool() | |
$dialog.Title = $Title | |
$null = $dialog.ShowDialog() | |
$dialog.FileNames | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment