Skip to content

Instantly share code, notes, and snippets.

@F1XI
F1XI / FolderPicker.ps1
Created July 29, 2022 15:53
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)
{
@F1XI
F1XI / gist:f9a66f36e4a3bb1773aafe93bd867852
Created July 25, 2022 07:46
Usage of FolderBrowserDialog in Powershell
[void] [System.Reflection.Assembly]::LoadWithPartialName('System.Windows.Forms')
function Get-Folder() {
param
(
[Parameter(Mandatory=$false)][string]$initialDirectory = $ENV:USERPROFILE
)
try {