Code/Function/Public/Get-Path.ps1
Function Get-Path { <# .SYNOPSIS GUI to choose path .DESCRIPTION This function opens a window to choose a specific path .PARAMETER RootFolder Folder in which the window will open .PARAMETER Description Window title .INPUTS You can pipe the value of the parameter (path) to this function / None .OUTPUTS System.Object[] / None .EXAMPLE Get-Path .LINK https://github.com/gisp497/psgisp #> [CmdletBinding()] param ( [Parameter( Mandatory = $false, HelpMessage = "help message" )] [string]$RootFolder = [Environment]::GetFolderPath('Desktop'), [Parameter( Mandatory = $false, HelpMessage = "help message" )] [string]$Description = 'Select Folder or File' ) Begin { #load assembly [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null } Process { #create object $OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog #set root folder $OpenFileDialog.initialDirectory = $RootFolder #remove filter $OpenFileDialog.filter = "All files (*.*)| *.*" #set windows title $OpenFileDialog.Title = $Description #show window $OpenFileDialog.ShowDialog() | Out-Null } End { #output value return $OpenFileDialog.filename } } |