Error when adding new AD user
我正在研究一个小的脚本,以使将用户添加到我们的广告更加容易。它只是一个单行的New-ADUser powershell脚本,要求输入。看起来像这样:
1 | New-ADUser -Name (Read-Host"User Name") -AccountExpirationDate 0 -CannotChangePassword 1 -ChangePasswordAtLogon 0 -PasswordNeverExpires 1 -Company (Read-Host"Company") -Department (Read-Host"Department") -Title (Read-Host"Title") -Manager (Read-Host"Manager's User Name") -GivenName (Read-Host"Full Name") -MobilePhone (Read-Host"Cell Phone Number") -State (Read-Host"State") -AccountPassword (Read-Host -AsSecureString"Password") -ProfilePath (Read-Host"Roaming Profile Path") -Path (Read-Host"AD Path to User") |
它要求提供所有应有的条件,但在输入所有内容后返回:" New-ADUser:无效的Win32 FileTime。行:1 char:11。我在命令中检查了该位置(它是" New-ADUser"之后的空格),但我不知道为什么它会返回该位置。
这是做我想要的事的有效方法吗?如何修复命令以不返回错误?这是我要输入的内容吗?
您必须更改:
1 | -AccountExpirationDate 0 |
with
1 | -AccountExpirationDate $null |
,否则您将无法为即将到期的帐户设置此参数。
此technet页面有错误。
对于Windows Server 2016,存在上述问题,并且上述解决方案不起作用(完全)。
我找到了一种解决方法。
是的,上面的Technet页面有错误;不幸的是,这也导致PowerShell脚本系统在解析脚本
时遇到问题
所以-错误#1-如果使用以
将
我找到了以下解决方案可以完全解决问题:
更改(如上所述)
将此参数移至LAST参数!否则,您将得到错误,错误地分析了下一项。您会注意到,在IDE中,参数以错误的颜色显示。