オプション説明
Filterファイルのフィルター。
“CSV (*.csv)|*.csv”
“All files (*.*)|*.*”
PowerShell
Add-Type -AssemblyName System.Windows.Forms
 
$dialog = New-Object System.Windows.Forms.OpenFileDialog
#$dialog.InitialDirectory = [Environment]::GetFolderPath("Desktop") # 初期フォルダ
$dialog.InitialDirectory = "C:\Users\username\Downloads"
$dialog.Filter = "All files (*.*)|*.*"                             # フィルタ設定
 
if ($dialog.ShowDialog() -eq [System.Windows.Forms.DialogResult]::OK) {
    $filePath = $dialog.FileName
    Write-Output "選択されたファイル: $filePath"
}