Q:

Do textbox while variable is empty in powershell

I'm new to powershell and I need some help with a script.
I have a simple code which loops while the user doesn't type a name :
do {$name = Read-Host "Choose a name "}
    while (!$name) {}

I try to use it for the GUI version but the loop doesn't stop :
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 

$box = {

$Form = New-Object System.Windows.Forms.Form 
$Form.Text = "Hostname"
$Form.Size = New-Object System.Drawing.Size(270,150) 
$Form.StartPosition = "CenterScreen"

$OKButton = New-Object System.Windows.Forms.Button
$OKButton.Location = New-Object System.Drawing.Size(165,75)
$OKButton.Size = New-Object System.Drawing.Size(75,23)
$OKButton.Text = "OK"
$OKButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$Form.AcceptButton = $OKButton
$Form.Controls.Add($OKButton)

$Label = New-Object System.Windows.Forms.Label
$Label.Location = New-Object System.Drawing.Size(10,15) 
$Label.Size = New-Object System.Drawing.Size(280,20) 
$Label.Text = "Choose a name :"
$Form.Controls.Add($Label) 

$TextBox = New-Object System.Windows.Forms.TextBox 
$TextBox.Location = New-Object System.Drawing.Size(10,40) 
$TextBox.Size = New-Object System.Drawing.Size(230,20) 
$Form.Controls.Add($TextBox) 

$Form.Topmost = $True

$Form.Add_Shown({$TextBox.Select()})
$result = $Form.ShowDialog()
return $TextBox.Text

}

do {&$box}
    while (!$TextBox.Text) {}

I think I'm missing something, but I don't know what... 
Sorry for my poor english, thanks in advance.

A:

Your textbox, being invoked, is never transmitted to its parent. Therefore, you need to assign your return value and works from there.    
do {$value = &$box }
while ([String]::IsNullOrWhiteSpace($value)) 
Write-Host $value -ForegroundColor Cyan

