2

When trying to create users from a file I get an error when -otherAttributes @{} is added to ps script. I am new to powershell and can not get it to work. Any guidance is appreciated. This is My code:

Import-Module ActiveDirectory
$OU = 'ou=Staging OU, dc=Domain, dc=net'
$usrfile = "\\servername\testuser.csv"

Import-Csv $usrfile | 
ForEach-Object {
     New-ADUser -SamAccountName $_.samaccountname -UserPrincipalName $_.Userprincipalname -Name $_.Name -DisplayName $_.displayname -GivenName $_.givenname -Surname $_.sn -Initials $_.initials -Title $_.title -OtherName $_.middlename `
-Description $_.description -Department $_.department -EmployeeID $_.employeeid -Path $OU -Country $_.c `
-OtherAttributes @{departmentNumber=$user.departmentnumber;localeID=$user.localid;extensionAttribute1=$user.extensionAttribute1;employeeType=$user.employeetype} `
-AccountPassword (ConvertTo-SecureString "Password" -AsPlainText -Force) -Enabled $true `
-PasswordNeverExpires $false -ChangePasswordAtLogon $true -PassThru 
    } > Import.log
4

3 回答 3

2

我的 AD 中的参数“-otherAttributes @{}”失败。我发现其他方式在 AD 中更改此值。

试试这个:

PS> Set-ADuser -identity joseiba -Clear 'msRTCSIP-PrimaryUserAddress'
PS> Set-ADuser -identity joseiba -Add @{'msRTCSIP-PrimaryUserAddress'='4213@grupofibratel.com'}

BR

于 2014-05-26T14:03:24.093 回答
0

您在其他属性的 ldapdisplayname 周围省略了 '

@{departmentNumber=$user.departmentnumber; 应该是:@{'departmentNumber'=$user.departmentnumber;

您需要在其他属性中的每个 ldapdisplayname 周围加上 ' .. 只是自己处理注释字段

于 2013-08-13T18:08:15.750 回答
0

在当前循环迭代中访问对象时,请确保您将所有 $ 都设置为 $_...。我看有些不是。

于 2012-05-10T16:20:51.667 回答