title: How to create an AD User with a Powershell GUI?
body: <p>I am trying to create a GUI that can create new AD Users. 
  My Problem: When I press the Button "Speichern" it does not use the Data in the textboxs to create the AD User. Instead this text comes in the command console: </p>
  
  <pre><code>New ADUser cmdlet at command pipeline location 1
  Specify values ​​for the following parameters:
  Surname:
  </code></pre>
  
  <p>If I enter the Surname it will create the User with this Surname.
  This is my Powershell script:</p>
  
  <pre><code>[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Drawing") 
  [void] [System.Reflection.Assembly]::LoadWithPartialName("System.Windows.Forms") 
  
  Import-Module ActiveDirectory
  
  #GUI Oberfläche
  $Form = New-Object System.Windows.Forms.Form
  $Form.Size = New-Object System.Drawing.Size(500,500)
  $Form.Text = "Benutzer hinzufügen"
  
  #-------Labels-----------
  #Label Benutzer hinzufügen
  $labeladduser = New-Object System.Windows.Forms.Label
  $labeladduser.Location = New-Object System.Drawing.Size(200,10) 
  $labeladduser.Size = New-Object System.Drawing.Size(200,30) 
  $labeladduser.Text = "Benutzer hinzufügen"
  $labeladduser.Name = "Benutzer hinzufügen"
  $Form.Controls.Add($labeladduser)
  
  #Label Vorname
  $Labelvorname = New-Object System.Windows.Forms.Label
  $Labelvorname.Location = New-Object System.Drawing.Size(10,50) 
  $Labelvorname.Size = New-Object System.Drawing.Size(100,20) 
  $Labelvorname.Text = "Vorname"
  $Labelvorname.Name = "Vorname"
  $Form.Controls.Add($Labelvorname)
  
  #Label Nachname
  $Labelnachname = New-Object System.Windows.Forms.Label
  $Labelnachname.Location = New-Object System.Drawing.Size(10,80) 
  $Labelnachname.Size = New-Object System.Drawing.Size(100,20) 
  $Labelnachname.Text = "Nachname"
  $Labelnachname.Name = "Nachname"
  $Form.Controls.Add($Labelnachname)
  
  #Label Vollständigername
  $LabelVn = New-Object System.Windows.Forms.Label
  $LabelVn.Location = New-Object System.Drawing.Size(10,110) 
  $LabelVn.Size = New-Object System.Drawing.Size(100,20) 
  $LabelVn.Text = "Vollständigername"
  $LabelVn.Name = "Vollständigername"
  $Form.Controls.Add($LabelVn)
  
  #Label Benutzeranmeldename
  $LabelBa = New-Object System.Windows.Forms.Label
  $LabelBa.Location = New-Object System.Drawing.Size(10,140) 
  $LabelBa.Size = New-Object System.Drawing.Size(150,20) 
  $LabelBa.Text = "Benutzeranmeldename"
  $LabelBa.Name = "Benutzeranmeldename"
  $Form.Controls.Add($LabelBa)
  
  #-------Buttons-------
  #Close GUI Button
  $BTcancel = New-Object System.Windows.Forms.Button
  $BTcancel.Location = New-Object System.Drawing.Size(400,180)
  $BTcancel.Size = New-Object System.Drawing.Size(75,23)
  $BTcancel.Text = "Cancel"
  $BTcancel.Name = "Cancel"
  $BTcancel.Add_Click({$Form.Close()})
  $Form.Controls.Add($BTcancel) 
  
  #Speichern Button
  $BTsave = New-Object System.Windows.Forms.Button
  $BTsave.Location = New-Object System.Drawing.Size(320,180)
  $BTsave.Size = New-Object System.Drawing.Size(75,23)
  $BTsave.Text = "Speichern"
  $BTsave.Name = "Speichern"
  $Form.Controls.Add($BTsave) 
  
  #------Textfields------
  #Textfeld Vorname
  $Textboxvorname = New-Object System.Windows.Forms.TextBox 
  $Textboxvorname.Location = New-Object System.Drawing.Size(200,50) 
  $Textboxvorname.Size = New-Object System.Drawing.Size(200,20) 
  $addv = $Textboxvorname.Text
  $Form.Controls.Add($Textboxvorname)
  
  #Textfeld Nachname
  $Textboxnachname = New-Object System.Windows.Forms.TextBox 
  $Textboxnachname.Location = New-Object System.Drawing.Size(200,80) 
  $Textboxnachname.Size = New-Object System.Drawing.Size(200,20) 
  $addn = $Textboxnachname.Text
  $Form.Controls.Add($Textboxnachname)
  
  #Textfeld Vollständigername
  $TextboxVa = New-Object System.Windows.Forms.TextBox 
  $TextboxVa.Location = New-Object System.Drawing.Size(200,110) 
  $TextboxVa.Size = New-Object System.Drawing.Size(200,20) 
  $addVa = $TextboxVa.Text
  $Form.Controls.Add($TextboxVa)
  
  #Textfeld Benutzeranmeldename
  $TextboxBa= New-Object System.Windows.Forms.TextBox 
  $TextboxBa.Location = New-Object System.Drawing.Size(200,140) 
  $TextboxBa.Size = New-Object System.Drawing.Size(200,20) 
  $addBa = $TextboxBa.Text
  $Form.Controls.Add($TextboxBa)
  
  #------Funktionen--------
  #Add User
  $BTsave.Add_Click({
  New-ADuser
   -Name $addVa
   -Path "Ou=Users, DC=domain, DC=com"
   -Givenname = $addv
   -Surname =$addn
   -SamAccountName $addBa
   -AccountPassword (ConvertT0-SecureString "&lt;redacted&gt;" -AsPlainText -Force)
  })
  
  [void] $Form.ShowDialog()
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/YzCtM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YzCtM.png" alt="enter image description here"></a>
  Does someone have a solution for my problem?</p>