A blog by Pilothouse Consulting
Virtual Image User and User Profile Creation PowerShell Script Update
For user profiles demos, it’s nice to have some sample profiles in there. For SharePoint 2007 image, we used a script to populate Active Directory users with the proper information and then just do an import to SharePoint. For SharePoint 2010 image, instead of using Active Directory. we are using local user accounts, so the script had to change. Now we take the user profile information from the same CSV file that’s used to create local accounts.
Here is the PowerShell script:
# SharePoint 2010 Workstation create users and user profiles script
# Pilothouse Consulting, Inc. Feel free to distribute and modify it.
$computer = [ADSI]"WinNT://$env:computername"
$userslist = import-csv users-list.csv | Select username, fullname, firstname, lastname, department, jobtitle, manager, skills, email
foreach($singleuser in $userslist)
{
$user = $computer.Create("user", $singleuser.username)
$user.SetPassword("Training45")
$user.SetInfo()
$user.FullName = $singleuser.fullname
$user.Description = "SharePoint sample user"
$user.SetInfo()
}
$site = Get-SPSite "http://abcuniversity"
$serverContext = Get-SPServiceContext $site
$upm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileManager($serverContext)
foreach($singleuser in $userslist)
{
$accountName = "abcuniversity\" + $singleuser.username
if ($upm.UserExists($accountName))
{
$up = $upm.GetUserProfile($accountName)
}
else
{
$up = $upm.CreateUserProfile($accountName)
write-host "user" $accountName "profile created"
}
$up["FirstName"].Value = $singleuser.firstname
$up["LastName"].Value = $singleuser.lastname
$up["PreferredName"].Value = $singleuser.fullname
$up["Department"].Value = $singleuser.department
$up["Title"].Value = $singleuser.jobtitle
$manager = "abcuniversity\" + $singleuser.manager
$up["Manager"].Value = $manager
$up["SPS-Skills"].Value = $singleuser.skills
$up.Commit()
write-host "user" $accountName "profile updated"
}
Here is the CSV file:
username,fullname,firstname,lastname,department,email,jobtitle,manager,skills
davegreen,Dave Green,Dave,Green,Graphic Design,DaveGreen@abcuniversity.com,Professor,bettytwain,Presenting
lucysmith,Lucy Smith,Lucy,Smith,Chemistry,LucySmith@abcuniversity.com,Professor,martharollings,Researching
bobjohnson,Bob Johnson,Bob,Johnson,Graphic Design,BobJohnson@abcuniversity.com,Student Researcher,davegreen,Researching
davesmith,Dave Smith,Dave,Smith,Graphic Design,DaveSmith@abcuniversity.com,Student Researcher,bobjohnson,Researching
martharollings,Martha Rollings,Martha,Rollings,Chemistry,MarthaRollings@abcuniversity.com,Department Head,administrator,Researching
judybright,Judy Bright,Judy,Bright,Chemistry,JudyBright@abcuniversity.com,Student Researcher,lucysmith,Presenting
tracywright,Tracy Wright,Tracy,Wright,Chemistry,TracyWright@abcuniversity.com,Student Researcher,lucysmith,Researching
alexbrown,Alex Brown,Alex,Brown,Chemistry,AlexBrown@abcuniversity.com,Professor,martharollings,Presenting
kellybrennan,Kelly Brennan,Kelly,Brennan,Chemistry,KellyBrennan@abcuniversity.com,Student Researcher,lucysmith,Researching
georgemason,George Mason,George,Mason,Graphic Design,GeorgeMason@abcuniversity.com,Student Researcher,davegreen,Researching
gregwalter,Greg Walter,Greg,Walter,Math,GregWalter@abcuniversity.com,Student Researcher,lisasimmons,Researching
clairejohnson,Claire Johnson,Claire,Johnson,Math,ClaireJohnson@abcuniversity.com,Department Head,administrator,Presenting
lisasimmons,Lisa Simmons,Lisa,Simmons,Math,LisaSimmons@abcuniversity.com,Professor,jeffbridges,Researching
jonstew,Jon Stew,Jon,Stew,Graphic Design,JonStew@abcuniversity.com,Professor,jeffbridges,Researching
bobbush,Bob Bush,Bob,Bush,Math,BobBush@abcuniversity.com,Student Researcher,lisasimmons,Presenting
marysimmons,Mary Simmons,Mary,Simmons,Math,MarySimmons@abcuniversity.com,Student Researcher,lisasimmons,Presenting
donnabridges,Donna Bridges,Donna,Bridges,Graphic Design,DonnaBridges@abcuniversity.com,Professor,bettytwain,Researching
jeffbridges,Jeff Bridges,Jeff,Bridges,Math,JeffBridges@abcuniversity.com,Department Head,administrator,Researching
jerryboss,Jerry Boss,Jerry,Boss,Graphic Design,JerryBoss@abcuniversity.com,Professor,bettytwain,Presenting
bettytwain,Betty Twain,Betty,Twain,Graphic Design,BettyTwain@abcuniversity.com,Department Head,administrator,Presenting
administrator,SharePoint Admin,SharePoint,Admin,Chemistry,administrator@abcuniversity.com,SharePointer,davegreen,SharePoint
You can modify the scripts for your own demo environment, or if you going through SharePoint Training DVD labs, just run these on the current image. All the future images will sample user profiles.
| Print article | This entry was posted by admin on August 12, 2010 at 6:13 pm, and is filed under SharePoint 2010, SharePoint Training DVD. Follow any responses to this post through RSS 2.0. You can leave a response or trackback from your own site. |


