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下的信息?
如果有人需要更多信息,请告诉我。
任何帮助,将不胜感激。谢谢。
喜福克斯 - 感谢您的答复。只是为了检查;在-ChangePasswordAtLogon $ true之后添加此直接? – jakeythehobo
ie New-ADUser -AccountPassword $ pass -Enabled $ true -ChangePasswordAtLogon $ true -OtherAttributes @ {“extensionattribute2”= $ _。extensionAttribute2} – jakeythehobo
你完全正确!我所做的只是包装你的命令,以适应StackExchange允许的80个字符。 – FoxDeploy