Select folder and write in a textbox the output powershell
<p>I have created an application in powershell, and now i need to add the GUI to the app.</p>

<p>In this application I need to give the user the opportunity to <strong>select</strong> or <strong>write</strong> the path of a folder in a textbok. I have written this piece of code but i haven't achieved to get the output of calling the <code>get-FolderLocation</code> function in the texbox that i create.</p>

<p><a href="https://i.stack.imgur.com/ej0jE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/ej0jE.png" alt="enter image description here"></a></p>

<p>Any ideas about how to achieve this?</p>

<pre><code>[void][System.Reflection.Assembly]::LoadWithPartialName( “System.Windows.Forms”)
[void][System.Reflection.Assembly]::LoadWithPartialName( “Microsoft.VisualBasic”)

#####Define the form size &amp; placement

$form = New-Object “System.Windows.Forms.Form”;
$form.Width = 500;
$form.Height = 150;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;

##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 25;
$textLabel1.Top = 15;
$textLabel1.Text = "select the folder";

############Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 150;
$textBox1.Top = 10;
$textBox1.width = 200;
$textBox1.Text = "selected folder"  

#############define select button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 360;
$button.Top = 85;
$button.Width = 100;
$button.Text = “Browse”;

############# the output of calling the get-Folder Location function must be shown in the textbox1

$button.Add_Click({get-Folderlocation}) ;

#############Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textBox1);

$form.ShowDialog();
$textBox1.Text



$selectedDirectory


function get-Folderlocation([string]$Message, [string]$InitialDirectory, [switch]$NoNewFolderButton)
{
    $browseForFolderOptions = 0
    if ($NoNewFolderButton) { $browseForFolderOptions += 512 }

    $app = New-Object -ComObject Shell.Application
    $folder = $app.BrowseForFolder(0, $Message, $browseForFolderOptions, $InitialDirectory)
    if ($folder) { $selectedDirectory = $folder.Self.Path } else { $selectedDirectory = '' }
    [System.Runtime.Interopservices.Marshal]::ReleaseComObject($app) &gt; $null
    return $selectedDirectory
}
</code></pre>