Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Powershell添加本地用户_Powershell - Fatal编程技术网

Powershell添加本地用户

Powershell添加本地用户,powershell,Powershell,我想创建一个Powershell Gui脚本,可以创建本地用户。这里的问题是,为什么代码需要一个参数?用-nopassword它就行了 代码: $button_BenutzerErstellen_OnClick= { $textBox6.Text $textBox7 = ConvertTo-SecureString -AsPlainText -Force if (($handler_textBox6.Text -eq 0) -or

我想创建一个Powershell Gui脚本,可以创建本地用户。这里的问题是,为什么代码需要一个参数?用-nopassword它就行了

代码:

    $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
}

使用
TextBox
es上的
Text
属性:

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

您正在尝试为New LocalUser cmdlet的Password属性指定字符串值,该属性不是有效的预期数据类型。 删除此项:

$textBox7 = ConvertTo-SecureString -AsPlainText -Force
并将else语句更改为:

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

您还可以将网络用户作为一个在线用户使用

NET USER username "password" /ADD

谢谢,但是为什么代码要我输入字符串-没有密码的工作,但它的密码要求我的字符串。