Skip to content

Instantly share code, notes, and snippets.

@lenicyl
Created December 20, 2021 06:19
Show Gist options
  • Save lenicyl/90e2cfc0e3fa098a1ed50bf4297fbf9c to your computer and use it in GitHub Desktop.
Save lenicyl/90e2cfc0e3fa098a1ed50bf4297fbf9c to your computer and use it in GitHub Desktop.
[Powershell] Open File Dialog
<# Source :
https://www.reddit.com/r/PowerShell/comments/m9iqz9/vs_code_open_file_dialog_not_taking_focus/
Thanks kind redditor
#>
Function Get-FileName {
$null=[System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms")
$OpenFileDialog = [System.Windows.Forms.OpenFileDialog]@{
InitialDirectory = "$env:USERPROFILE\Desktop"
}
$null=$OpenFileDialog.ShowDialog()
$OpenFileDialog.FileName
}
$file = Get-FileName
Write-Host $file
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment