2012-10-15 54 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中參數以錯誤的顏色顯示。