簡體   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