Solved

Powershell script to import users to Active Directory Server 2008

Posted on 2012-03-29
14
357 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 500 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
Forrester Webinar: xMatters Delivers 261% ROI

Guest speaker Dean Davison, Forrester Principal Consultant, explains how a Fortune 500 communication company using xMatters found these results: Achieved a 261% ROI, Experienced $753,280 in net present value benefits over 3 years and Reduced MTTR by 91% for tier 1 incidents.

 
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 500 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 22

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 22

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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

This article outlines the process to identify and resolve account lockout in an Active Directory environment.
Previously, on our Nano Server Deployment series, we've created a new nano server image and deployed it on a physical server in part 2. Now we will go through configuration.
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

730 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