繁体   English   中英

添加新的AD用户时出错

[英]Error when adding new AD user

我正在研究一个小的脚本,以使将用户添加到我们的广告更加容易。 它只是一行要求输入的New-ADUser powershell脚本。 看起来像这样:

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”之后的空格),但我不知道为什么它将返回该位置。

这是做我想要的有效方法吗? 如何修复命令以不返回错误? 这是我要输入的内容吗?

您必须更改:

-AccountExpirationDate 0

-AccountExpirationDate $null

或者您根本无法为即将到期的帐户设置此参数。

technet页面有错误。

对于Windows Server 2016,存在上述问题,并且上述解决方案不起作用(完全)。

我找到了一种解决方法。

是的,上面的Technet页面有错误; 不幸的是,这也导致PowerShell脚本系统在解析脚本时遇到问题

所以-错误#1-如果您使用命令New-ADUser作为参数指定为0 ,则会收到错误New-ADUser : Not a valid win32 FileTime.

当您将0更改为$null ,将出现错误#2- The term '(the next parameter in your command)' is not recognized as the name of a cmdlet, function

我发现以下解决方案可以完全解决问题:

  1. 更改(如上所述) -AccountExpirationDate $null

  2. 将此参数移至LAST参数! 否则,您将得到错误,错误地分析了下一项。 您会注意到,在IDE中,参数以错误的颜色显示。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM