Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Powershell: How to export users from AD into a CSV then import it back into AD

Posted on 2013-01-17
13
Medium Priority
?
481 Views
Last Modified: 2013-01-22
Hello,

I did submit the following question stated on the link but is more relevant to powershell than  Active Directory..

http://www.experts-exchange.com/Software/Server_Software/File_Servers/Active_Directory/Q_27997464.html

Thanks for your help,
0
Comment
Question by:namerg
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 8
  • 3
  • 2
13 Comments
 
LVL 31

Expert Comment

by:Henrik Johansson
ID: 38787239
Export:
get-aduser -filter "samaccountname -like 'a*'" -properties givenName,sn,Department| export-csv filename.csv

Open in new window


Import changes:
import-csv filename.csv |foreach
{
  set-aduser $_.samaccountname -givenName $_.givenName -surname $_.sn -department $_.department
} 

Open in new window

0
 

Author Comment

by:namerg
ID: 38787501
@henjoh09, what about if the export comes from a certain OU ?
0
 
LVL 31

Assisted Solution

by:Henrik Johansson
Henrik Johansson earned 2000 total points
ID: 38787544
If you want to export a specific OU, you can add -SearchBase parameter to Get-ADUser cmdlet.

-SearchBase 'OU=child,OU=parent,DC=domain,DC=local'

Open in new window

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:namerg
ID: 38787562
Like this:
get-aduser -SearchBase 'OU=child,OU=parent,DC=domain,DC=local' -filter "samaccountname -like 'a*'" -properties givenName,sn,Department| export-csv filename.csv

Open in new window

0
 

Author Comment

by:namerg
ID: 38787809
Hmm, I am getting the CSV blank. :(
0
 

Author Comment

by:namerg
ID: 38788086
When i execute
Get-ADUser -SearchBase "OU=OU,DC=DOMAIN,DC=COM" -filter {objectClass -eq "user"} -properties sn,givenName,title,department,employeeid,employeenumber,samaccountname| export-csv TEST.csv

Open in new window


I get the following wrong headers:
"Department","DistinguishedName","EmployeeID","EmployeeNumber","Enabled","GivenName","Name","ObjectClass","ObjectGUID","SamAccountName","SID","Surname","Title","UserPrincipalName"

I want the ones I specified in -properties

Thanks for your help,
0
 

Author Comment

by:namerg
ID: 38788119
Guru subsun, or footech...I am crying for your help. ;(
0
 

Accepted Solution

by:
namerg earned 0 total points
ID: 38788252
Never mind, I got it.

I used
Get-ADUser -filter * -Properties sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber,sAMAccountName  -SearchBase "OU=UPI,DC=domain,DC=com" | Select-Object sn,givenName,department,title,telephoneNumber,employeeID,employeeNumber,sAMAccountName | export-csv TEST.csv -notype

Open in new window

0
 
LVL 41

Expert Comment

by:footech
ID: 38789316
@namerg - In reply to your comment "...but never got a reply when I was crying for help".  Sorry, but unless you've waited at least a day for a reply there's no reason to complain.  We're all volunteers here and the times we're available can be unpredictable.  You were right to award the points as you did.
0
 

Author Comment

by:namerg
ID: 38789343
Thanks footech for your email. Sorry. Hey, about the other question that you helped me I am going to split points between you and subsun, is that ok ?
0
 
LVL 41

Expert Comment

by:footech
ID: 38789759
That's fine.  No need to ask.  If I ever feel strongly about how points are awarded I'll object, but that rarely happens.
0
 
LVL 31

Expert Comment

by:Henrik Johansson
ID: 38789809
As question also asked for importing the changes back, I think you should had included my original comment instead of the followup as answer.
I should had read the linked question thread more careful as it contains some followup comments about what properties you wanted to change/add and could based on that maybe have given you a more complete script from the beginning.
Maybe not so good idea to link to a question you've requested to delete as the reference will be broken... :) About the delete request comment, it had been better to use "request attention"-button to ask moderators to change zone for question.

However, glad to help by pointing in correct direction./Henrik
0
 

Author Closing Comment

by:namerg
ID: 38804797
Well, henjoh09 gave me the hint but never got a reply when I was crying for help. No hard feelings if you do not accept my answer as solution.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
This process allows computer passwords to be managed and secured without using LAPS. This is an improvement on an existing process, enhanced to store password encrypted, instead of clear-text files within SQL
To efficiently enable the rotation of USB drives for backups, storage pools need to be created. This way no matter which USB drive is installed, the backups will successfully write without any administrative intervention. Multiple USB devices need t…
This tutorial will walk an individual through the process of transferring the five major, necessary Active Directory Roles, commonly referred to as the FSMO roles from a Windows Server 2008 domain controller to a Windows Server 2012 domain controlle…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question