I am a very new user of powershell. I am reading through some of the documentation and I need to develop a script that will prompt a user for some information, such as an ID and Password. I found an example of some code that is building a nice looking window, but it only has one text box and I need to have two. I have tried to modify the code, but I am not having any success. Here is the code I am using. Can someone let me know what I might be doing incorrectly. I also need to mask the password field so that characters are not displayed. I have not figured this piece out yet, but if you have a quick answer, I would appreciate it.
Add-Type -AssemblyName System.Windows.Forms
Add-Type -AssemblyName System.Drawing
$form = New-Object System.Windows.Forms.Form
$form.Text = ‘Resource Load’
$form.Size = New-Object System.Drawing.Size(350,350)
$form.StartPosition = ‘CenterScreen’
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(75,260)
$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)
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(150,260)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = ‘Cancel’
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,20)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ‘Enter your credentials:’
$form.Controls.Add($label)
$label2 = New-Object System.Windows.Forms.Label
$label2.Location = New-Object System.Drawing.Point(10,40)
$label2.Size = New-Object System.Drawing.Size(280,40)
$label2.Text = ‘Please enter your ID’
$form.Controls.Add($label2)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,80)
$textBox.Size = New-Object System.Drawing.Size(260,80)
$form.Controls.Add($textBox)
$label3 = New-Object System.Windows.Forms.Label
$label3.Location = New-Object System.Drawing.Point(10,110)
$label3.Size = New-Object System.Drawing.Size(280,110)
$label3.Text = ‘Please enter your password’
$form.Controls.Add($label3)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,160)
$textBox.Size = New-Object System.Drawing.Size(260,160)
$form.Controls.Add($textBox)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($result -eq [System.Windows.Forms.DialogResult]::OK)
{
$x = $textBox.Text
$x
$y = $textBox2.Text
$y
}