?
Solved

Powershell script to import users to Active Directory Server 2008

Posted on 2012-03-29
14
Medium Priority
?
372 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
Has Powershell sent you back into the Stone Age?

If managing Active Directory using Windows Powershell® is making you feel like you stepped back in time, you are not alone.  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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

For anyone that has accidentally used newSID with Server 2008 R2 (like I did) and hasn't been able to get the server running again because you were unlucky (as I was) and had no backups - I was able to get things working by doing a Registry Hive rec…
Here's a look at newsworthy articles and community happenings during the last month.
This tutorial will walk an individual through configuring a drive on a Windows Server 2008 to perform shadow copies in order to quickly recover deleted files and folders. Click on Start and then select Computer to view the available drives on the se…
This tutorial will walk an individual through the steps necessary to join and promote the first Windows Server 2012 domain controller into an Active Directory environment running on Windows Server 2008. Determine the location of the FSMO roles by lo…
Suggested Courses
Course of the Month8 days, 20 hours left to enroll

764 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