我尝试使用PowerShell脚本和CSV将用户导入AD。
这是我的脚本(删除了名字):
$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 :(得分:0)
要设置扩展属性,请使用以下语法:
Set-ADUser –Identity $ThisUser -add @{"extensionattribute1"="MyString"}
您还可以使用New-ADUser的-OtherAttributes参数指定其他属性
因此,将此集成到您的代码中,我尝试创建新用户并同时指定扩展属性。
Import-Csv .\adimport.csv | New-ADUser -AccountPassword $pass -Enabled $true `
-ChangePasswordAtLogon $true `
-OtherAttributes @{"extensionattribute2"=$_.extensionAttribute2}
Lemme知道这是否有帮助:)