2015-08-28 68 views
0

我试图使用PowerShell脚本和CSV将用户导入到AD中。使用CSV和PowerShell将用户导入到AD中 - ExtensionAttribute2问题

这里是我的脚本(其名称删除):

$pass = ConvertTo-SecureString "passwordhere" -AsPlainText -Force 

Import-Csv .\adimport.csv | New-ADUser -AccountPassword $pass -Enabled $true -ChangePasswordAtLogon $true 

Get-ADUser -Filter * -SearchBase 'OU=<ouname>,OU=<ouname>,OU=<ouname>,OU=<ouname>,DC=<name>,DC=<name>,DC=<name>,DC=<name>' -Properties userPrincipalName | foreach { Set-ADUser $_ -UserPrincipalName "$($_.samaccountname)@<domainname>"} 

这是我的CSV的样子:

Name Username SamAccountName GivenName Surname DisplayName Description Path Enabled Postalcode StreetAddress City Title Office Company extensionAttribute2 officephone 

一切工作正常,在将用户导入(进入正确的OU),和除extensionAttribute2外,所有信息都会更新。

有没有人知道我需要更改以获取AD中的extensionAttribute2,以便在运行脚本时从CSV导入extensionAttribute2下的信息?

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

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

回答

0

要设置扩展属性,使用此语法:

Set-ADUser –Identity $ThisUser -add @{"extensionattribute1"="MyString"} 

您也可以使用新ADUser便有

所以,这个集成到你的代码,我的-OtherAttributes PARAM指定其他属性m试图创建新用户,并同时指定Extension Attribute。

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

还是让我知道,如果这有助于:)

+0

喜福克斯 - 感谢您的答复。只是为了检查;在-ChangePasswordAtLogon $ true之后添加此直接? – jakeythehobo

+0

ie New-ADUser -AccountPassword $ pass -Enabled $ true -ChangePasswordAtLogon $ true -OtherAttributes @ {“extensionattribute2”= $ _。extensionAttribute2} – jakeythehobo

+0

你完全正确!我所做的只是包装你的命令,以适应StackExchange允许的80个字符。 – FoxDeploy

相关问题