2017-01-30 71 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