Bulk Imports using CSV (cross post from TurboChargeAD.org)
As some of you may know I am doing some guest blogging over at TurboChargeAD.org 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
Param($file,$OU,[switch]$whatif,[switch]$verbose)
if($verbose){$VerbosePreference = "Continue"}
if(!(test-path $file))
{
throw " File NOT found!"
return
}
if(!$ou)
{
# 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 | %{$_.name}
# 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 `
-verbose:$verbose
$MyUser
}


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!
~Glenn
P.S. Thanks for ditching the line count… made stealing your code a real pain