Powershell OpenFileDialog is not showing up

Recently I was writing scripts that should run on a Windows 7 machine. One task was to select a file and read it. So I used the usual snippet:

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
[void]$OpenFileDialog.ShowDialog()

I ran the script from PowerShell ISE during development and everything worked fine but when the users executed the script, the file dialog did not open up. Then I came across this page here and it said ShowHelp solves the problem. I changed the script to:

$OpenFileDialog = New-Object System.Windows.Forms.OpenFileDialog
$OpenFileDialog.ShowHelp = $true
[void]$OpenFileDialog.ShowDialog()

I am not sure why, but this solved the problem and did not cause any other side effect. I am wondering what ShowHelp actual does because it seems to have no visible effect.

PowerShell – wait for completion of external process

Often when working with PowerShell you want to start an external process and wait for its completion. An example of this might look like this:

Write-Host "Show before starting Notepad"

Notepad.exe

Write-Host "Show after closing Notepad"

But this script prints the second line directly after starting notepad. There are several solutions possible, but this one has proved very useful.

Write-Host "Show before starting Notepad"

Notepad.exe | Out-Null

Write-Host "Show after closing Notepad"

Simply add Out-Null after the invocation of notepad and PowerShell will wait until it continues executing the script.