When working on Windows, you always have the benefit of making use of integrated Windows features. One of these is OpenFileDialog
, which comes with the PresentationFramework
library. The following function demonstrates a simple usage of it to retrieve and return selected files within the GUI:
function Show-OpenFileDialog { <# .SYNOPSIS Shows up an open file dialog. .EXAMPLE Show-OpenFileDialog #> [CmdletBinding()] param ( [Parameter(Mandatory=$false, Position=0)] [System.String] $Title ='Windows PowerShell', [Parameter(Mandatory=$false, Position=1)] [Object] $InitialDirectory ="$Home\Documents", [Parameter(Mandatory=$false, Position=2)] [System.String] $Filter ='PowerShell-files|*.ps1|Everything|*.*' ) Add-Type -AssemblyName PresentationFramework $dialog = New-Object -TypeName Microsoft.Win32.OpenFileDialog $dialog.Title =$Title $dialog.InitialDirectory =$InitialDirectory $dialog...