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

x
?
Solved

Powershell script to import users to Active Directory Server 2008

Posted on 2012-03-29
14
Medium Priority
?
378 Views
Last Modified: 2014-09-05
Anyone have a powershell script that will import users into Active Directory on a 2008 Domain via ,csv file.

I exported these users to a CSV file from another server, So i just need the powershell script to import from the csv file.

Thanks
0
Comment
Question by:Markolong
[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
  • 4
  • 2
  • 2
  • +3
14 Comments
 
LVL 27

Accepted Solution

by:
KenMcF earned 2000 total points
ID: 37784451
You can use the MS ad cmdlets or Quest free AD cmdelts. Depending on what attributes you what to populate. Here is an example of something you could do

¿Foreach ($User in (import-csv C:\Scripts\QAD_User_Import.csv)){
        $QADUserprops = @{
            FirstName = $User.FirstName
            LastName = $User.LastName
            City = $User.City
            PhoneNumber = $User.PhoneNumber
            StateOrProvince = $User.StateorProvince
            Name = $User.Name
            PostalCode = $User.PostalCode
            UserPrincipalName = $User.UserPrincipalName
            samaccountname = $User.samaccountname
            ParentContainer = "OU=POSH_GROUP,DC=Devlab,DC=Local"
            UserPassword = "PGHPoshPass1"
            DisplayName = $User.Displayname
            Description = $User.Description
            Office = $User.Office
            email = $User.email
        }
        
    $EmployeeID = $User.EmployeeID


    New-QADUser @QADUserProps -ObjectAttributes @{employeeID=$employeeID}
}

Open in new window

0
 
LVL 3

Expert Comment

by:y4utech
ID: 37784578
You can check the following link to use csvde to import user in AD.

http://xp2600.blogspot.in/2008/04/how-to-import-users-to-active-directory.html
0
 

Author Comment

by:Markolong
ID: 37784616
The top example is the script assuming im already in the import active directory module?
0
Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

 
LVL 27

Expert Comment

by:KenMcF
ID: 37784686
the one I posted is using the Quest cmdlets. So you will need to add

add-pssnapin *Quest*

if you want an exmaple using the MS cmdlets I can post
0
 
LVL 27

Assisted Solution

by:KenMcF
KenMcF earned 2000 total points
ID: 37784700
Here is an example using MS cmdlets.

¿
import-module ActiveDirectory
$Pass = ConvertTo-SecureString "PoshPass1" -AsPlainText -Force
Foreach ($User in (import-csv C:\Scripts\MS_User_Import.csv)){
    $Userprops = @{
        GivenName = $User.GivenName
        Surname = $User.SurName
        City = $User.City
        OfficePhone = $User.OfficePhone
        State = $User.State
        Name = $User.Name
        PostalCode = $User.PostalCode
        UserPrincipalName = $User.UserPrincipalName
        samaccountname = $User.Samaccountname
        path = "OU=POSH_GROUP,DC=Devlab,DC=Local"
        AccountPassword = $Pass
        enabled = $TRUE
        country = $User.Country
        DisplayName = $User.DisplayName
        Description = $User.Description
        Office = $User.Office
        email = $User.Email
    }

    $EmployeeID = $User.EMployeeID

    New-ADUser @UserProps -OtherAttributes @{employeeID=$EmployeeID}

}

Open in new window

0
 
LVL 23

Expert Comment

by:yo_bee
ID: 37784742
I know this is a powershell question, but about about using somthing like csvde -i  
http://technet.microsoft.com/en-us/library/cc732101(v=ws.10).aspx
This is free and it is part of windows.
0
 
LVL 23

Expert Comment

by:Malli Boppe
ID: 37785542
I have used csvde in the past and is really  easy to use.

http://www.computerperformance.co.uk/Logon/Logon_CSVDE_Bulk.htm

or you can use Admanager which has 30 day license. can be used to set  password as well. I have use in the past and works really well

http://www.manageengine.com/products/ad-manager/download.html
0
 

Author Comment

by:Markolong
ID: 37785844
Does all of these solutions work for importing computers as well and other objects
0
 
LVL 27

Expert Comment

by:KenMcF
ID: 37786168
Are you doing a domain migration?

If you are take a look at ATMT
http://www.microsoft.com/download/en/details.aspx?id=8377


You can create new computer objects with new-adcomputer or new-qadcomputer

Groups using new-adgroup and new-qadgroup
0
 
LVL 23

Expert Comment

by:Malli Boppe
ID: 37786426
I don't think so .You need to readd them to domain
0
 
LVL 23

Expert Comment

by:yo_bee
ID: 37790942
You can export a template by filtering to a user distinguishedName.  review to the csv file for all your attributes and if you can confirm that they are all available for an import I think you are good then.

 csvde -m -f OUTPUT.CSV  -b USERNAME DOMAINNAME *-s SERVERNAME -d "cn=users,DC=DOMAINNAME,DC=Microsoft,DC=Com" -r "(objectClass=user)"
0
 
LVL 2

Expert Comment

by:zulazen
ID: 40091691
I have an example of how to do this on the main page of my blog:

http://ps1scripting.blogspot.com/
0

Featured Post

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

After seeing many questions for JRNL_WRAP_ERROR for replication failure, I thought it would be useful to write this article.
A walk-through example of how to obtain and apply new DID phone numbers to your cloud PBX enabled users that are configured in Office 365. Whether you have 1, 10 or 100+ users in your tenant, it's quite easy to get them phone-enabled and making/rece…
This tutorial will show how to configure a single USB drive with a separate folder for each day of the week. This will allow each of the backups to be kept separate preventing the previous day’s backup from being overwritten. The USB drive must be s…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

636 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