gpt4 book ai didi

Powershell:New-LocalUser - 找不到接受参数 'True' 的位置参数

转载 作者:行者123 更新时间:2023-12-02 23:09:14 25 4
gpt4 key购买 nike

我一直在关注this guide尝试编写一个 powershell 脚本来将新的本地用户添加到 Windows。

我需要用户名、全名、描述和密码,并检查 PasswordNeverExpiresUserMayNotChangePassword。为此,我写了以下内容:

$Password = Read-Host -AsSecureString -Prompt 'Create password for new user account:'
New-LocalUser -Name "NewUser" -FullName "New User" -Description "New Execution Account" -Password $Password -PasswordNeverExpires $true -UserMayNotChangePassword $true

但是,当运行它时,出现以下错误:

New-LocalUser : A positional parameter cannot be found that accepts argument 'True'. At line:2 char:1
+ New-LocalUser -Name "NewUser" -FullName "New User" -Description "New ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidArgument: (:) [New-LocalUser], ParameterBindingException
+ FullyQualifiedErrorId : PositionalParameterNotFound,Microsoft.PowerShell.Commands.NewLocalUserCommand

如果有人能看到我哪里出错了,我将不胜感激任何帮助或建议,谢谢!

最佳答案

最后两个参数是开关参数。您不需要向他们传递参数。只需按原样提供它们就足够了。像这样:

$Password = Read-Host -AsSecureString -Prompt 'Create password for new user account:'
New-LocalUser -Name "NewUser" -FullName "New User" -Description "New Execution Account" -Password $Password -PasswordNeverExpires -UserMayNotChangePassword

关于Powershell:New-LocalUser - 找不到接受参数 'True' 的位置参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48279118/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com