Solved

Powershell script to import users to Active Directory Server 2008

Posted on 2012-03-29
14
326 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
  • 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
 
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 21

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
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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 21

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Disabling the Directory Sync Service Account in Office 365 will stop directory synchronization from working.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
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 to another domain controller. Log onto the new domain controller with a user account t…
This tutorial will walk an individual through the process of configuring their Windows Server 2012 domain controller to synchronize its time with a trusted, external resource. Use Google, Bing, or other preferred search engine to locate trusted NTP …

707 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now