2012-10-15 67 views
0

我正在研究一个小脚本,以便更容易地将用户添加到AD中。这只是一个新的ADUser PowerShell脚本,要求输入。它看起来像这样:添加新的AD用户时出错

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") 

,它要求一切都像它应该,但输入返回后一切:“新ADUser便有:不是有效的Win32 FILETIME在行:1个字符:11”我在命令中检查了这个位置(这是“New-ADUser”之后的空格),我不知道它为什么会返回该位置。

这是做我想做的一种有效的方式吗?我如何解决我的命令不返回错误?这是我输入的点吗?

回答

3

你必须改变:

-AccountExpirationDate 0 

-AccountExpirationDate $null 

,或者你可以简单地未设置此参数为unexpiring帐户。

This technet页面有错误。

+0

啊是的,[this](http://ss64.com/ps/new-aduser.html)源代码是一样的。 – elock37

0

对于Windows Server 2016,上述问题存在,上述解决方案无法工作(完全)。

我找到了解决办法。

是的,上面的Technet页面有错误;不幸的是,这也导致了PowerShell脚本系统,具有解析脚本

所以一个问题 - 错误#1 - 如果你使用命令New-ADUser0作为参数指定的,你会得到错误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中参数以错误的颜色显示。