简体   繁体   English

运行Powershell脚本以使用Import-Csv和New-QADUser将用户从csv导入到Active Directory时出错

[英]Error when running powershell script to import users from csv using Import-Csv and New-QADUser into Active Directory

My script looks like this: 我的脚本如下所示:

$Users = Import-Csv "C:\users.csv"
foreach ($User in $Users)
{
    New-QADUser -Name $User.Name `
        -ParentContainer $User.OU `
        -FirstName $User.FirstName `
        -LastName $User.LastName `
        -UserPassword $User.userPassword `
        -SamAccountName $User.sAMAccountName `
}

When I run it I get the following error: 当我运行它时,出现以下错误:

DefaultNamingContext                               Type            
--------------------                               ----            
DC=example,DC=domain,DC=org                  ActiveDirectory 
The server is unwilling to process the request. (Exception from HRESULT: 0x80072035)
At :line:5 char:12
+   New-QADUser <<<<  -Name $User.Name `

My CSV looks like this: 我的CSV如下所示:

Name,FirstName,LastName,sAMAccountName,UserPassword,OU
Joe Bob,Joe,Bob,jb241277,4gh60b4,"OU=2010,OU=Sub,OU=Users,OU=MAIN,DC=example,DC=domain,DC=org"

Not sure what is going on, any help would be appreciated. 不知道发生了什么,任何帮助将不胜感激。 This is a child domain in a forest on Win2K8 Ent. 这是Win2K8 Ent上林中的子域。

It is possible that this action is being attempted against a Global Catalog for some reason. 出于某种原因,可能针对全局目录尝试执行此操作。 Your code works fine for me, but I get the error when I attempt to do it against a GC, which is expected. 您的代码对我来说很好用,但是尝试对GC进行操作时出现错误,这是预期的。 The connect-QADService cmdlet specifies where you want to connect. connect-QADService cmdlet指定要连接的位置。 If you're setting this before your new-qaduser code, double-check to make sure that "-UseGlobalCatalog" is not in there. 如果要在new-qaduser代码之前进行设置,请仔细检查以确保其中没有“ -UseGlobalCatalog”。

As a troubleshooting step you can try to specify a specific Domain Controller to see if that changes your error. 作为故障排除步骤,您可以尝试指定特定的域控制器,以查看这是否会更改您的错误。

$Users = Import-Csv "C:\users.csv"
foreach ($User in $Users)
{
    New-QADUser -Name $User.Name `
        -ParentContainer $User.OU `
        -FirstName $User.FirstName `
        -LastName $User.LastName `
        -UserPassword $User.userPassword `
        -SamAccountName $User.sAMAccountName `
        -Service $DomainController `
}

That will tell it to perform the action against a specific domain controller and not a Global Catalog. 这将告诉它对特定的域控制器而不是全局目录执行操作。

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

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