Stuck in building PS Form AD-search

Hi Experts,

I wonder if someone could help me out on this one.

I am trying to build  a form that searches for a User by UserName 

should Return values (displayname and description) in  a read-only textbox  and (pager) in a editable one

the search will be started after entering  a usename and hit the "ZOEK" button the information coming back is just to be certain the correct user is entered

The pager attribute will be abused for Badgecode

So the form is used to search for user and add or replace  the  Pager attribute data.

Code is below and sorry for the Dutch phrases..

# Importeerd AD Module
import-module activedirectory


clear
######################## FORMULIER BEGIN #############################################################################################################

function button ($title, $Gebruikersnaam, $VolledigeNaam, $MicrosectieNummer, $BadgeCode )

{

###################Load Assembly for creating form & button######

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

#####Define the form size & placement

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

##############Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 5;
$textLabel1.Top = 50;

$textLabel1.Text = $Gebruikersnaam;

##############Define text label2

$textLabel2 = New-Object “System.Windows.Forms.Label”;
$textLabel2.Left = 5;
$textLabel2.Top = 75;

$textLabel2.Text = $VolledigeNaam;

##############Define text label3

$textLabel3 = New-Object “System.Windows.Forms.Label”;
$textLabel3.Left = 5;
$textLabel3.Top = 100;
$textLabel3.Text = $MicrosectieNummer;

##############Define text label4
$textLabel4 = New-Object “System.Windows.Forms.Label”;
$textLabel4.Left = 5;
$textLabel4.Top = 130;

$textLabel4.Text = $BadgeCode;

############Define textbox1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 150;
$textBox1.Top = 50;
$textBox1.width = 100;


############Define textBox3 for autofill

$textBox3 = New-Object “System.Windows.Forms.TextBox”;
$textBox3.Left = 150;
$textBox3.Top = 75;
$textBox3.width = 200;


############ Define textBox4 for autofill

$textBox4 = New-Object “System.Windows.Forms.TextBox”;
$textBox4.Left = 150;
$textBox4.Top = 100;
$textBox4.width = 100;

############Define textbox2 for input
$textBox2 = New-Object “System.Windows.Forms.TextBox”;
$textBox2.Left = 150;
$textBox2.Top = 125;
$textBox2.width = 100;

#############define ZOEK button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 100;
$button.top = 45;
$button.Width = 45;
$button.height = 20
$button.Text = “Zoek”;

#############define Badge Toevoegen/Wijzigen button
$button1 = New-Object “System.Windows.Forms.Button”;
$button1.Left = 150;
$button1.top = 150;
$button1.Width = 150;
$button1.height = 20
$button1.Text = “Badge Toevoegen/Wijzigen ”;

############# This is when you have to close the form after getting values
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$textBox3.Text;
$textBox4.Text;
$textBox2.Text;

$form.Close();};

########### Define Button actions ############
$button.Add_Click({$user = Get-ADuser -identity $textBox1.Text -Properties * | Select -Property Name,DisplayName,Description,Pager}) ;

#$button.Add_Click({$user = Get-ADuser -identity $textBox1.Text -Properties | Select -Property Name,DisplayName,Description,Pager}) ;

$button1.Add_Click({ Set-ADUser -Identity $textBox1.Text -Replace @{Pager = $TextBox2.Text }})
$button1.Add_Click($eventHandler) ;

#############Define default values for the input boxes
$defaultValue = “”
$textBox1.Text = $defaultValue;
$textBox2.Text = $defaultValue;
$textBox3.Text = $user.DisplayName;
$textBox4.Text = $user.Description;

#############Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($button1);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textLabel2);
$form.Controls.Add($textLabel3);
$form.Controls.Add($textLabel4);
$form.Controls.Add($textBox1);
$form.Controls.Add($textBox3);
$form.Controls.Add($textBox4);
$form.Controls.Add($textBox2);

$ret = $form.ShowDialog();

################# return values generated and picked up by create accounts script below Formulier Einde###############################################

return $textBox1.Text,$textBox2.Text,$textBox3.Text,$textBox4.Text


$return= button “Badge Koppelen” "Gebruikers Naam" “Volledige Naam” “Microsectie nr.” “Badge Code”
$return[0]
$return[1]
$return[2]
$return[3]
$return[4]

}
######################## FORMULIER EINDE ######################################################