Posts RSS Comments RSS 253 Posts and 411 Comments till now

Bulk Imports using CSV (cross post from

As some of you may know I am doing some guest blogging over at and below is a link to the second such article.

Here is the Link: Bulking Importing User from CSV file using Quest cmdlets

Here is the code

#requires -pssnapin Quest.ActiveRoles.ADManagement

if($verbose){$VerbosePreference = "Continue"}

if(!(test-path $file))
   throw " File NOT found!"

    # Setting the OU to the Users container
    $ou = "CN=Users,{0}" -f ([ADSI]"").distinguishedName[0]

Write-Verbose " Using File: $file"
Write-Verbose " Using OU: $ou"

foreach($user in (Import-Csv $file))
    $props = @{}
    # Getting a list property names.
    $propNames = $user | Get-Member -MemberType properties | %{$}
    # Foreach of the property names add an entry in the hash table with
    # the key being the property name and value being the value from the object
    foreach($prop in $propNames)
        # This removes quotes if they exist
    $value = $user.$prop -replace "’|`"",""
        $props += @{$prop=$value}
    # Create User using the displayname as the CN
    $MyUser = new-qaduser -name $user.displayName `
                          -ObjectAttributes $props `
                          -parent $OU `
                          -whatif:$whatif `

One Response to “Bulk Imports using CSV (cross post from”

  1. on 17 Oct 2008 at 6:19 pmglnsize

    That is by far the shortest Brandon AD script I have ever seen… It really is amazing how many lines of code cmdlets can eliminate.

    Keep it up, I for one have learned a ton from your work!


    P.S. Thanks for ditching the line count… made stealing your code a real pain 😉

Trackback this post | Feed on Comments to this post

Leave a Reply

You must be logged in to post a comment.