Powershell script to create Active Directory user Profiles and MySites

This is awesome…check it out!  A powershell script that will create a profile for every AD user, then creates there My Site!

 [System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint.Portal")

$dom = "LDAP://CN=Users;DC=training;DC=corp"
$root = new-object DirectoryServices.DirectoryEntry $dom

$selector = new-object DirectoryServices.DirectorySearcher
$selector.SearchRoot = $root

$adobj = $selector.findall() | where {$_.properties.objectcategory -match "CN=Person"}
$spsite = new-object Microsoft.SharePoint.SPSite("http://sharepoint2007:100")
$context = [Microsoft.Office.Server.ServerContext]::GetContext($spsite)
$pmanager = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

ForEach ($person in $adobj)
{
$prop = $person.properties
$prop.cn

$exists = $pmanager.UserExists($prop.cn)

if ($exists -eq $false)
{
$pmanager.CreateUserProfile($prop.cn)
}

$up = $pmanager.GetUserProfile($prop.cn)
$up.CreatePersonalSite()

}