powershellimportactive-directoryquest

Import users attributes from CSV file to Active Directory ( Updating AD )


I am trying to import some of the parameters from csv file to AD.I want to match the data by e-mail.I am using Quest ActiveRoles Management Shell.

Import-Csv c:\Test.csv |ForEach-Object {
Set-QADUser 'ou=User,ou=Accounts,ou=PL,dc=test,dc=com'  
if(($_.E-mail Address)=mail){ $_.HR Department Code -department 
$_.HR Department Code -telephoneNumber $_.Reports to L1 Formal Name -manager}
else
(Write-Host 'ERROR, User not present in AD')
}

What is wrong with this loop? Is it possible to do it with this white spaces like in "HR Department Code" , I tried replacing it with variables but it does not work. I was using this idea to write this. I am using $_. to match it with my column/att name from csv

http://dmitrysotnikov.wordpress.com/2008/10/03/update-active-directory-user-accounts-from-csv-file/

**Update

Code that I am currently using:

Import-Csv 'C:\Test_Peoplesoft.csv' | foreach-object{set-qaduser -mail $_.'E-mail Address' -Department $_.'HR Department Code'  -telephoneNumber $_.'HR Department Code'}

Right now nothing is happening, it just starts and never stops, looks like nothing happens. I have skipped manager field since there has to be a login and in my csv file is right now in this field full name of a supervisor.


Solution

  • I dont think that your if statement is actually comparing your csv email and your AD email. Just use the email as the identity parameter:

      Import-Csv $file | foreach-object{set-qaduser $_.email -Department $_.department -Manager $_.manager -Title $_.title -ObjectAttributes @{employeeID=($_.employeeID)}}
    

    Obviously there are some attributes I added for the example that you aren't using. Also replace my header names with your actual header names. I also try to avoid spaces in my headers in CSVs. the none standard attributes like employee ID and extension attributes etc will need to be set in the -objectAttributes