Browse for folder locks up.

Wanted to add browsing to a folder, to my script and I found this example:

Add-Type -AssemblyName System.Windows.Forms
$FolderBrowser = New-Object System.Windows.Forms.FolderBrowserDialog -Property @{
    SelectedPath = 'C:\Temp’
}
 
[void]$FolderBrowser.ShowDialog()
$FolderBrowser.SelectedPath

The first time I run it, it runs fine. But, if I run it again, it locks up my PowerShell ISE and I have to end the task from Task Manager.

In fact every example I have found runs fine the first time, but then locks up if I run it again.

Can someone help?