I'm trying to get the output of my GUI script to display in the output filed... however it's not working.. I see that it $returns but won't place in the $output field... any suggestions?
function button ($title, $srv, $GB, $VL, $scope, $rtr, $gtw, $sbm, $psid, $adr, $stid) {
#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 = 359;
$form.Height = 670;
$form.Text = $title;
$form.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen;
#Define the output box
$outputBox = New-Object System.Windows.Forms.TextBox
$outputBox.Location = New-Object System.Drawing.Size(10,395)
$outputBox.Size = New-Object System.Drawing.Size(322,200)
$outputBox.MultiLine = $True
$outputBox.ScrollBars = "Vertical"
$Form.Controls.Add($outputBox)
#Define text label1
$textLabel1 = New-Object “System.Windows.Forms.Label”;
$textLabel1.Left = 10;
$textLabel1.Top = 17;
$textLabel1.Width = 80
$textLabel1.Text = $srv;
#Define text label2
$textLabel2 = New-Object “System.Windows.Forms.Label”;
$textLabel2.Left = 10;
$textLabel2.Top = 54;
$textLabel1.Width = 80
$textLabel2.Text = $GB;
#Define text label3
$textLabel3 = New-Object “System.Windows.Forms.Label”;
$textLabel3.Left = 10;
$textLabel3.Top = 94;
$textLabel1.Width = 80
$textLabel3.Text = $VL;
#Define text label4
$textLabel4 = New-Object “System.Windows.Forms.Label”;
$textLabel4.Left = 10;
$textLabel4.Top = 132;
$textLabel4.Width = 80
$textLabel4.Text = $scope;
#Define text label5
$textLabel5 = New-Object “System.Windows.Forms.Label”;
$textLabel5.Left = 10;
$textLabel5.Top = 172;
$textLabel5.Width = 80
$textLabel5.Text = $rtr;
#Define text label6
$textLabel6 = New-Object “System.Windows.Forms.Label”;
$textLabel6.Left = 10;
$textLabel6.Top = 212;
$textLabel6.Width = 80
$textLabel6.Text = $gtw;
#Define text label7
$textLabel7 = New-Object “System.Windows.Forms.Label”;
$textLabel7.Left = 10;
$textLabel7.Top = 253;
$textLabel7.Width = 80
$textLabel7.Text = $sbm;
#Define text label8
$textLabel8 = New-Object “System.Windows.Forms.Label”;
$textLabel8.Left = 10;
$textLabel8.Top = 293;
$textLabel8.Width = 80
$textLabel8.Text = $psid;
#Define text label9
$textLabel9 = New-Object “System.Windows.Forms.Label”;
$textLabel9.Left = 10;
$textLabel9.Top = 333;
$textLabel9.Width = 80
$textLabel9.Text = $adr;
#Define text label10
$textLabel10 = New-Object “System.Windows.Forms.Label”;
$textLabel10.Left = 10;
$textLabel10.Top = 373;
$textLabel10.Width = 80
$textLabel10.Text = $stid;
#Define text box1 for input
$textBox1 = New-Object “System.Windows.Forms.TextBox”;
$textBox1.Left = 200;
$textBox1.Top = 12;
$textBox1.width = 126;
#Define text box2 for input
$textBox2 = New-Object “System.Windows.Forms.TextBox”;
$textBox2.Left = 200;
$textBox2.Top = 47;
$textBox2.width = 126;
#Define text box3 for input
$textBox3 = New-Object “System.Windows.Forms.TextBox”;
$textBox3.Left = 200;
$textBox3.Top = 87;
$textBox3.width = 126;
#Define text box4 for input
$textBox4 = New-Object “System.Windows.Forms.TextBox”;
$textBox4.Left = 200;
$textBox4.Top = 127;
$textBox4.width = 126;
#Define text box5 for input
$textBox5 = New-Object “System.Windows.Forms.TextBox”;
$textBox5.Left = 200;
$textBox5.Top = 167;
$textBox5.width = 126;
#Define text box6 for input
$textBox6 = New-Object “System.Windows.Forms.TextBox”;
$textBox6.Left = 200;
$textBox6.Top = 207;
$textBox6.width = 126;
#Define text box7 for input
$textBox7 = New-Object “System.Windows.Forms.TextBox”;
$textBox7.Left = 200;
$textBox7.Top = 247;
$textBox7.width = 126;
#Define text box8 for input
$textBox8 = New-Object “System.Windows.Forms.TextBox”;
$textBox8.Left = 200;
$textBox8.Top = 287;
$textBox8.width = 126;
#Define text box9 for input
$textBox9 = New-Object “System.Windows.Forms.TextBox”;
$textBox9.Left = 200;
$textBox9.Top = 327;
$textBox9.width = 126;
#Define text box10 for input
$textBox10 = New-Object “System.Windows.Forms.TextBox”;
$textBox10.Left = 200;
$textBox10.Top = 367;
$textBox10.width = 126;
#Define default values for the input boxes
$defaultValue = “”
$textBox1.Text = $defaultValue;
$textBox2.Text = $defaultValue;
$textBox3.Text = $defaultValue;
$textBox4.Text = $defaultValue;
$textBox5.Text = $defaultValue;
$textBox6.Text = $defaultValue;
$textBox7.Text = $defaultValue;
$textBox8.Text = $defaultValue;
$textBox9.Text = $defaultValue;
$textBox10.Text = $defaultValue;
#define OK button
$button = New-Object “System.Windows.Forms.Button”;
$button.Left = 8;
$button.Top = 600;
$button.Width = 100;
$button.Text = “Ok”
$button.DialogResult = [System.Windows.Forms.DialogResult]::OK
#define Cancel button
$CancelButton = New-Object "System.Windows.Forms.Button";
$CancelButton.Left = 232;
$CancelButton.Top = 600;
$CancelButton.Width = 100;
$CancelButton.Text = "Cancel"
$CancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
#This is when you have to close the form after getting values
$eventHandler = [System.EventHandler]{
$textBox1.Text;
$textBox2.Text;
$textBox3.Text;
$textBox4.Text;
$textBox5.Text;
$textBox6.Text;
$textBox7.Text;
$textBox8.Text;
$textBox9.Text;
$textBox10.Text;
$form.Close();};
$button.Add_Click($eventHandler) ;
#Add controls to all the above objects defined
$form.Controls.Add($button);
$form.Controls.Add($CancelButton);
$form.Controls.Add($textLabel1);
$form.Controls.Add($textLabel2);
$form.Controls.Add($textLabel3);
$form.Controls.Add($textLabel4);
$form.Controls.Add($textLabel5);
$form.Controls.Add($textLabel6);
$form.Controls.Add($textLabel7);
$form.Controls.Add($textLabel8);
$form.Controls.Add($textLabel9);
$form.Controls.Add($textLabel10);
$form.Controls.Add($textBox1);
$form.Controls.Add($textBox2);
$form.Controls.Add($textBox3);
$form.Controls.Add($textBox4);
$form.Controls.Add($textBox5);
$form.Controls.Add($textBox6);
$form.Controls.Add($textBox7);
$form.Controls.Add($textBox8);
$form.Controls.Add($textBox9);
$form.Controls.Add($textBox10);
$ret = $form.ShowDialog();
#return values
return $textBox1.Text, $textBox2.Text, $textBox3.Text, $textBox4.Text, $textBox5.Text, $textBox6.Text, $textBox7.Text, $textBox8.Text, $textBox9.Text, $textBox10.Text
}
$return= button “DHCP Request Info” “DHCP Server:” “Scope ID:” “VLAN ID:” "Group Branch:" "Router:" "Gateway:" "SubnetMask:" "PeopleSoft ID:" "Address:" "Station ID:"
$return[0]
$return[1]
$return[2]
$return[3]
$return[4]
$return[5]
$return[6]
$return[7]
$return[8]
$return[9]
$return[10]