使用CSV将用户导入广告&;PowerShell-ExtensionAttribute2问题

使用CSV将用户导入广告&;PowerShell-ExtensionAttribute2问题,powershell,csv,active-directory,Powershell,Csv,Active Directory,我正在尝试使用PowerShell脚本和CSV将用户导入AD 以下是我的脚本(已删除名称): 一切正常,用户被导入(到正确的OU中),除了extensionAttribute2之外,所有信息都被更新 有人知道我需要做什么更改才能在AD中获取extensionAttribute2,以便在运行脚本时从CSV导入extensionAttribute2下的信息吗 如果有人需要更多信息,请告诉我 任何帮助都将不胜感激。谢谢。要设置扩展属性,请使用以下语法: Set-ADUser –Identity $T

我正在尝试使用PowerShell脚本和CSV将用户导入AD

以下是我的脚本(已删除名称):

一切正常,用户被导入(到正确的OU中),除了extensionAttribute2之外,所有信息都被更新

有人知道我需要做什么更改才能在AD中获取extensionAttribute2,以便在运行脚本时从CSV导入extensionAttribute2下的信息吗

如果有人需要更多信息,请告诉我


任何帮助都将不胜感激。谢谢。

要设置扩展属性,请使用以下语法:

 Set-ADUser –Identity $ThisUser -add @{"extensionattribute1"="MyString"}
还可以使用-OtherAttributes参数为New ADUser指定其他属性

因此,将其集成到代码中,我尝试创建新用户,同时指定扩展属性

Import-Csv .\adimport.csv | New-ADUser -AccountPassword $pass -Enabled $true `
  -ChangePasswordAtLogon $true `
  -OtherAttributes  @{"extensionattribute2"=$_.extensionAttribute2}

让我知道这是否有用:)

你好,福克斯-谢谢你的回复。只是检查一下;在-ChangePasswordAtLogon$true?即New ADUser-AccountPassword$pass-Enabled$true-ChangePasswordAtLogon$true-OtherAttributes@{“extensionattribute2”=$\uu0.extensionattribute2}之后直接添加此项。您完全正确!我所做的只是将您的命令包装成StackExchange中允许的80个字符。@FoxDeply好的,所以我尝试了这个,这是我收到的错误消息:New ADUser:无法验证参数“OtherAttributes”上的参数。参数为null或参数集合的元素包含null值。+。。。herAttributes@{“extensionattribute2”=$\uU2.extensionattribute2}+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~类别信息:InvalidData:(:)[New ADUser],ParameterBindingValidationException+FullyQualifiedErrorId:ParameterArgumentValidationError,Microsoft.ActiveDirectory.Management.Commands.NewAdUseri如果有帮助,我将在工作日使用extensionAttribute2。我在CSV上extensionAttribute2下写的一个例子是;周一至周五上午9点至下午5点
 Set-ADUser –Identity $ThisUser -add @{"extensionattribute1"="MyString"}
Import-Csv .\adimport.csv | New-ADUser -AccountPassword $pass -Enabled $true `
  -ChangePasswordAtLogon $true `
  -OtherAttributes  @{"extensionattribute2"=$_.extensionAttribute2}