需要帮助将包含名字和姓氏的 CSV 导入到 Active Directory。

huangapple go评论49阅读模式
英文:

Need help importing csv with first and last names to Active Directory

问题

我有一个.csv文件,其中包含名字(firstname)、姓氏(lastname)和员工编号(employeenumber)等列,但只有在我添加名称(name)和显示名称(Displayname)列时,我才能将CSV文件导入Active Directory,否则它会完全忽略名字和姓氏列,我不确定为什么。

如果不添加名称和显示名称列,它甚至都不会工作,但当我添加这些列后,它可以正常工作,但帐户中没有添加名字或姓氏,似乎只使用了名称列。我正在使用以下命令导入文件 -

Import-Csv .\New-Users.csv
    | New-ADUser -Enabled $True -AccountPassword (ConvertTo-SecureString Pass123456 -AsPlainText -force)
英文:

I have a .csv file with the columns firstname, lastname, and employeenumber, but I am only able to import the csv into Active Directory if I add name and Displayname columns, since it completely disregards the firstname and lastname columns and I'm not sure why.

Without adding the name and Displayname columns it won't even work, and then when I do add those it works but there is no first or last name added to the accounts so it's just ignoring those columns and only taking from the name column it seems. I am using this command to import the file -

Import-Csv .\New-Users.csv 
    | New-ADUser -Enabled $True -AccountPassword (ConvertTo-SecureString Pass123456 -AsPlainText -force)

答案1

得分: 0

你的问题最可能的原因是你的CSV列与cmdlet的参数不匹配。例如,firstname列应该被命名为givenname,以绑定到-GivenName参数,而lastname应该被重命名为surname,以绑定到-Surname参数。在CSV中进行这些更改应该可以解决问题。

除非你正确命名列,否则cmdlet无法确定哪个列应该绑定到哪个参数。 参见ValueFromPipelineByPropertyName参数以更好地了解PowerShell如何从管道绑定参数。

英文:

The most likable cause of your issue is that your CSV columns don't match with cmdlet's parameters. For example, the firstname column should be named givenname to be bound to the -GivenName parameter and lastname should be renamed to surname to be bound to the -Surname parameter. Changing this in your CSV should fix the immediate problem.

The cmdlet can't determine what column should be bound to which parameter unless you name the columns properly. See ValueFromPipelineByPropertyName argument to get a better understanding of how PowerShell bounds arguments from pipeline.

huangapple
  • 本文由 发表于 2023年3月7日 09:50:13
  • 转载请务必保留本文链接:https://go.coder-hub.com/75657369.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定