none
Exporting AD Users to CSV, editing/updating, then importing back into AD

    Question

  • Hi guys,

     

    I am very new to Powershell and need some help. I would like to export all users to a CSV, file ( with only the details name, department, description, title, company,and office ) update the details I want to for each user, save the CSV file, then upload it back into AD to overwrite/update the users.

    I can export what I want just fine into a CSV with:

    get-aduser -filter * -properties department,description,title,company,office | Select-Object name,department,description,title,company,office | Export-CSV C:\adusers.csv

     

    Then I can go in and update each attribute, but am having problems uploading back into AD

     

    Any help would be appreciated

     

    Thanks

     

    Kieran

    Thursday, October 11, 2012 7:56 PM

Answers

  • Well I tested with my suggestion and it worked, so I modified the file for some changes, re-ran it and it still worked without an error, the help file for the Set-ADUser cmdlet says that you use the -Replace parameter to replace one or more values of a property that cannot be modified using a cmdlet parameter.

    I changed every value for the properties you are trying to edit, and did not need to use the replace, so all those properties are able to be modified using the cmdlet parameters for the specified property.

    Is your command all on one line, or is it on two lines like it shows above?


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.


    Friday, October 12, 2012 1:10 PM
  • Hi,

    I would like suggest you remove -replace parameter and try the script again. Based on my understanding, the parameter is used to modify multi-value attibutes, as you want to change some different attributes, not multi-value attributes, so please remove the parameter.

    Hope this helps.

    Regards,

    Yan Li


    Yan Li

    TechNet Community Support

    Tuesday, October 16, 2012 6:02 AM
    Moderator

All replies

  • Take a look at the Set-ADUser cmdlet, you would do something like so

    Import-CSV C:\adusers.csv | ForEach-Object { Set-ADUser -Identity $_.sAMAccountName -Name $_.Name -Company $_.Comapny }....and so on, you will also need to get the sAMAccountName when exporting, to use with the identity parameter


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.

    • Proposed as answer by Bigteddy Thursday, October 11, 2012 8:26 PM
    • Unproposed as answer by kb123nz Thursday, October 11, 2012 9:27 PM
    Thursday, October 11, 2012 8:05 PM
  • Thanks clayman,

    So this is what I have now:

    Import-CSV C:\adusers.csv | ForEach-Object { Set-ADUser -Identity $_.sAMAccountName -Company $_.Company -department $_.department -description $_.description -title $_.title -office $_.office  }

    I get an error:

    Set_ADUser : replace

    At line:1 char: 56

    I then edited it to:

    Import-CSV C:\adusers.csv | ForEach-Object { Set-ADUser -replace @ {-Identity $_.sAMAccountName -Company $_.Company -department $_.department -description $_.description -title $_.title -office $_.office  }}

    However I then get an error "The has literal was incomplete" at line 1 char 69

    Thursday, October 11, 2012 9:05 PM
  • Well I tested with my suggestion and it worked, so I modified the file for some changes, re-ran it and it still worked without an error, the help file for the Set-ADUser cmdlet says that you use the -Replace parameter to replace one or more values of a property that cannot be modified using a cmdlet parameter.

    I changed every value for the properties you are trying to edit, and did not need to use the replace, so all those properties are able to be modified using the cmdlet parameters for the specified property.

    Is your command all on one line, or is it on two lines like it shows above?


    If you find that my post has answered your question, please mark it as the answer. If you find my post to be helpful in anyway, please click vote as helpful.


    Friday, October 12, 2012 1:10 PM
  • Hi,

    I would like suggest you remove -replace parameter and try the script again. Based on my understanding, the parameter is used to modify multi-value attibutes, as you want to change some different attributes, not multi-value attributes, so please remove the parameter.

    Hope this helps.

    Regards,

    Yan Li


    Yan Li

    TechNet Community Support

    Tuesday, October 16, 2012 6:02 AM
    Moderator
  • Thanks Clayman. It is all on one line if that helps.

    Monday, October 22, 2012 8:36 PM