简体   繁体   English

添加新的AD用户时出错

[英]Error when adding new AD user

I'm working on a small script to make adding users to our AD easier. 我正在研究一个小的脚本,以使将用户添加到我们的广告更加容易。 It's just a one line New-ADUser powershell script that asks for inputs. 它只是一行要求输入的New-ADUser powershell脚本。 It looks like this: 看起来像这样:

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

It asks for everything like it should but after inputting everything it returns: "New-ADUser : Not a valid Win32 FileTime. At line:1 char:11." 它要求提供所有应有的条件,但在输入所有内容后返回:“ New-ADUser:无效的Win32 FileTime。行:1 char:11。” I checked that location in the command (it's the space after "New-ADUser") and I don't know why it would return that. 我在命令中检查了该位置(它是“ New-ADUser”之后的空格),但我不知道为什么它将返回该位置。

Is this an efficient way of doing what I want? 这是做我想要的有效方法吗? How can I fix my command to not return the error? 如何修复命令以不返回错误? Is it what I'm inputting into the spots? 这是我要输入的内容吗?

You have to change: 您必须更改:

-AccountExpirationDate 0

with

-AccountExpirationDate $null

or you can simply not set this parameter for an unexpiring account. 或者您根本无法为即将到期的帐户设置此参数。

This technet page has an error. technet页面有错误。

For Windows Server 2016 the problem above exists, and the solution above does not work (completely). 对于Windows Server 2016,存在上述问题,并且上述解决方案不起作用(完全)。

I have found a workaround. 我找到了一种解决方法。

Yes, the Technet page above has an error; 是的,上面的Technet页面有错误; unfortunately, that also results in the PowerShell scripting system having a problem parsing the script 不幸的是,这也导致PowerShell脚本系统在解析脚本时遇到问题

So - Error #1 - If you use the command New-ADUser as specified with 0 as the parameter, you get error New-ADUser : Not a valid win32 FileTime. 所以-错误#1-如果您使用命令New-ADUser作为参数指定为0 ,则会收到错误New-ADUser : Not a valid win32 FileTime.

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

I found the following solution to completely solve the problem: 我发现以下解决方案可以完全解决问题:

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

  2. Move this parameter to the LAST Parameter! 将此参数移至LAST参数! Otherwise, you then end up with the error where the next item is incorrectly parsed. 否则,您将得到错误,错误地分析了下一项。 You'll note that in the IDE where the parameter shows up in the wrong color. 您会注意到,在IDE中,参数以错误的颜色显示。

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

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