簡體   English   中英

在Active Directory中添加用戶可提供未找到錯誤目錄對象的功能

[英]Adding User In Active Directory gives Error Directory Object not found powershell

嗨,大家好,我正在使用以下代碼將用戶添加到活動目錄,但我收到了未找到目錄對象的錯誤消息

$NewUser = Read-Host "New Username"
$firstname = Read-Host "First Name"
$Lastname = Read-Host "Last Name"
$NewName = "$firstname $lastname"


New-ADUser -SamAccountName $NewUser -Name $NewName -GivenName $firstname -Surname   
$lastname -Path "ou=Users,DC=mydomain,DC=local" -AccountPassword (Read-Host "New Password"   
-AsSecureString)

我認為您沒有真正查看Get-Help New-ADUser -Full因為它指定了(請注意第二個要點):

 -Path <string> Specifies the X.500 path of the Organizational Unit (OU) or container where the new object is created. In many cases, a default value will be used for the Path parameter if no value is specified. The rules for determining the default value are given below. Note that rules listed first are evaluated first and once a default value can be determined, no further rules will be evaluated. In AD DS environments, a default value for Path will be set in the following cases: - If the cmdlet is run from an Active Directory PowerShell provider drive, the parameter is set to the current path of the provider drive. - If the cmdlet has a default path, this will be used. For example: in New-ADUser, the Path parameter would default to the Users container. - If none of the previous cases apply, the default value of Path will be set to the default partition or naming context of the target domain. 

因此,它應該默認為您的“用戶” OU,而您實際上不需要指定它。 另外,我認為您在使用它的上下文中需要-DisplayName而不是-Name,並且對於該上下文,可能是-Name而不是-SamAccountName。 嘗試這個:

New-ADUser -Name $NewUser -DisplayName $NewName -GivenName $firstname -Surname $lastname -AccountPassword (Read-Host "New Password" -AsSecureString)

請記住,默認情況下該帳戶將被創建為禁用狀態。 -Enabled $true添加到您的命令以使其創建一個啟用的帳戶。 這確實需要提供有效的密碼。 如果密碼無效,仍然會創建該帳戶,但是該帳戶沒有密碼,因此不會啟用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM