Hello
I have a little problem with my script. Because I want to save the input of the user in a variable, but do not know exactly how to do it. I need help from you.
Best regards Ramon
Add-Type -AssemblyName System.Windows.Forms
GUI selber
$Form = New-Object system.Windows.Forms.Form
$Form.Text = “PC-Infos”
$Form.TopMost = $true
$Form.Width = 612
$Form.Height = 418
Textfeld
$listView1 = New-Object system.windows.Forms.ListView
$listView1.Text = “listView”
$listView1.Width = 398
$listView1.Height = 167
$listView1.location = new-object system.drawing.point(74,184)
$Form.controls.Add($listView1)
Benutzer hinzufügen Button
$button1 = New-Object system.windows.Forms.Button
$button1.Text = “Benutzer hinzufügen”
$button1.Width = 147
$button1.Height = 32
$button1.location = new-object system.drawing.point(75,44)
$button1.Font = “Microsoft Sans Serif,10”
$Form.controls.Add($button1)
$button1.Add_Click({
$form = New-Object System.Windows.Forms.Form
Titel
$form.Text = ‘Automatisierung für Benutzer anlegen’
$form.Size = New-Object System.Drawing.Size(500,400)
$form.StartPosition = ‘CenterScreen’
OK-Button
$okButton = New-Object System.Windows.Forms.Button
$okButton.Location = New-Object System.Drawing.Point(25,325)
$okButton.Size = New-Object System.Drawing.Size(75,23)
$okButton.Text = ‘OK’
$okButton.DialogResult = [System.Windows.Forms.DialogResult]::OK
$OKButton.Add_Click({$x=$TextBox.Text;$Form.Close()})
$form.AcceptButton = $OKButton
$form.Controls.Add($OKButton)
Cancel-Button
$cancelButton = New-Object System.Windows.Forms.Button
$cancelButton.Location = New-Object System.Drawing.Point(120,325)
$cancelButton.Size = New-Object System.Drawing.Size(75,23)
$cancelButton.Text = ‘Cancel’
$cancelButton.DialogResult = [System.Windows.Forms.DialogResult]::Cancel
$CancelButton.Add_Click({$Form.Close()})
$form.CancelButton = $cancelButton
$form.Controls.Add($cancelButton)
Abfrage 1
$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 = ‘Benutzername:’
$form.Controls.Add($label)
$textBox = New-Object System.Windows.Forms.TextBox
$textBox.Location = New-Object System.Drawing.Point(10,40)
$textBox.Size = New-Object System.Drawing.Size(260,20)
$form.Controls.Add($objtextBox)
Abfrage 2
#$label = New-Object System.Windows.Forms.Label
#label.Location = New-Object System.Drawing.Point(10,80)
#label.Size = New-Object System.Drawing.Size(280,20)
#label.Text = ‘Passwort:’
#form.Controls.Add($label)
#textBox = New-Object System.Windows.Forms.TextBox
#textBox.Location = New-Object System.Drawing.Point(10,100)
#textBox.Size = New-Object System.Drawing.Size(260,20)
#form.Controls.Add($textBox)
Abfrage 2.1
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,140)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ‘Passwort wiederholen:’
$form.Controls.Add($label)
#$textBox = New-Object System.Windows.Forms.TextBox
#$textBox.Location = New-Object System.Drawing.Point(10,160)
#textBox.Size = New-Object System.Drawing.Size(260,20)
#$form.Controls.Add($textBox)
Abfrage 3
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,200)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ‘Vollständiger Name:’
$form.Controls.Add($label)
#$textBox = New-Object System.Windows.Forms.TextBox
#textBox.Location = New-Object System.Drawing.Point(10,220)
#textBox.Size = New-Object System.Drawing.Size(260,20)
#$form.Controls.Add($textBox)
Abfrage 4
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,200)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = ‘Beschreibung:’
$form.Controls.Add($label)
#$textBox = New-Object System.Windows.Forms.TextBox
#textBox.Location = New-Object System.Drawing.Point(10,220)
#textBox.Size = New-Object System.Drawing.Size(260,20)
#form.Controls.Add($textBox)
Abfrage 5
$label = New-Object System.Windows.Forms.Label
$label.Location = New-Object System.Drawing.Point(10,200)
$label.Size = New-Object System.Drawing.Size(280,20)
$label.Text = get-localuser
$form.Controls.Add($label)
$form.Topmost = $true
$form.Add_Shown({$textBox.Select()})
$result = $form.ShowDialog()
if ($OKButton.Add_Click)
{
write-host $textBox.Text
}
})
####### Benutzer löschen Button
$button2 = New-Object system.windows.Forms.Button
$button2.Text = “Benutzer löschen”
$button2.Width = 147
$button2.Height = 32
$button2.location = new-object system.drawing.point(314,44)
$button2.Font = “Microsoft Sans Serif,10”
$Form.controls.Add($button2)
Benutzer sehen Button
$button3 = New-Object system.windows.Forms.Button
$button3.Text = “Benutzer sehen”
$button3.Width = 147
$button3.Height = 32
$button3.location = new-object system.drawing.point(75,94)
$button3.Font = “Microsoft Sans Serif,10”
$Form.controls.Add($button3)
Exit Button
$button4 = New-Object system.windows.Forms.Button
$button4.Text = “Exit”
$button4.Width = 147
$button4.Height = 32
$button4.location = new-object system.drawing.point(313,93)
$button4.Font = “Microsoft Sans Serif,10”
$Form.controls.Add($button4)
$button4.Add_Click({
$form.Close()
})
damit das GUI angezeigt wird.
[void]$Form.ShowDialog()
$Form.Dispose()