How to use open file dialog in PowerShell

When you are working with files sometimes is easier use the open file dialog or select the files.

For example when you use the Import-Csv cmdlet to retrieve data from a csv you can use these lines:

$File = New-Object System.Windows.Forms.OpenFileDialog -Property @{

    InitialDirectory = [Environment]::GetFolderPath(‘Desktop’)


$null = $File.ShowDialog()

$FilePath = $File.FileName

Import-Csv $FilePath

Then work with all data in the Csv file.

The most important part of this code is the class System.Windows.Forms.OpenFileDialog that allows create the object $File

I have another post working with .csv files to see how process the records but for now I want to show you this nice feature.

Thanks – Gracias  – Dhanyavaad


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s