2017-01-30 94 views
1

我想創建一個可以創建本地用戶的Powershell Gui腳本。這裏的問題是,爲什麼代碼要求參數?使用-nopassword它的作品。Powershell添加本地用戶

代碼:

$button_BenutzerErstellen_OnClick= 
{ 
$textBox6.Text 
$textBox7 = ConvertTo-SecureString -AsPlainText -Force 


       if (($handler_textBox6.Text -eq 0) -or 
      ($handler_textBox7.TextLength -eq 0)) { 
     [System.Windows.Forms.MessageBox]::Show("Bitte füllen Sie alle Kriterien aus." , "Combat 19") 

     }else{ 
      New-LocalUser $textBox6.Text -Password $textBox7 -Description $textBox1.Text 
} 

回答

1

使用Text財產上TextBox ES:

New-LocalUser $textBox6.Text -Password $textBox7 -Description $textBox1.Text 
+0

謝謝,但爲什麼代碼問我一個字符串? -nopassword工作,但與密碼它問我的字符串。 –

0

你試圖給新-LocalUser cmdlet的密碼屬性是無效預期的數據類型的字符串值。 刪除此:

$textBox7 = ConvertTo-SecureString -AsPlainText -Force 

,並更改其他聲明如下:

New-LocalUser $textBox6.Text -Password $($textBox7.Text | ConvertTo-SecureString -AsPlainText -Force) -Description $textBox1.Text 
0

您可以將用戶的網絡用戶也爲oneliner

NET USER username "password" /ADD