Skip to content

Instantly share code, notes, and snippets.

@F1XI
Created July 29, 2022 15:53
Show Gist options
  • Save F1XI/1e946621b7701d92a05216d7e43b79f7 to your computer and use it in GitHub Desktop.
Save F1XI/1e946621b7701d92a05216d7e43b79f7 to your computer and use it in GitHub Desktop.
Better than BrowseForFolder
# add following 2 dlls to the script directory
# dlls from https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Shell
# and from https://www.nuget.org/packages/Microsoft-WindowsAPICodePack-Core
# for some mystical reason the script does not run in ISE but console will do
Add-Type -Path "$($PSScriptRoot)\Microsoft.WindowsAPICodePack.Shell.dll"
$dialog = New-Object Microsoft.WindowsAPICodePack.Dialogs.CommonOpenFileDialog
$dialog.IsFolderPicker = $true;
if ($Dialog.ShowDialog() -eq [Microsoft.WindowsAPICodePack.Dialogs.CommonFileDialogResult]::Ok)
{
$dialog.FileName
}
$dialog.Dispose()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment