0

我正在编写一个小脚本,以便更轻松地将用户添加到我们的 AD。它只是要求输入的一行 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。在 line:1 char:11。” 我在命令中检查了那个位置(它是“New-ADUser”之后的空格),我不知道它为什么会返回那个位置。

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

4

2 回答 2

4

你必须改变:

-AccountExpirationDate 0

-AccountExpirationDate $null

或者您可以简单地不为未到期的帐户设置此参数。

技术网页面有错误。

于 2012-10-15T18:45:05.217 回答
0

对于 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. 将此参数移至最后一个参数!否则,您最终会遇到下一个项目被错误解析的错误。您会注意到在 IDE 中参数以错误的颜色显示。

于 2016-10-28T15:44:40.037 回答