Solved

Powershell script to import users to Active Directory Server 2008

Posted on 2012-03-29
14
352 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This article explains how to install and use the NTBackup utility that comes with Windows Server.
This tutorial will walk an individual through setting the global and backup job media overwrite and protection periods in Backup Exec 2012. Log onto the Backup Exec Central Administration Server. Examine the services. If all or most of them are stop…
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 …

856 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