SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lt me know if this is possible :

i have around 100 local user and i want to add them to user profile.Can any on help me out to create scripts to add the user to user profile.

Also i want the scripts to edit any particular property for the said user.

share|improve this question
up vote 5 down vote accepted

Here is simple code example to get you started:

Add-PSSnapin Microsoft.SharePoint.PowerShell

$siteUrl = "http://mycoolsite/"
$accountName = "MyAccountName"

$site = Get-SPSite $siteUrl 
$context = Get-SPServiceContext($site) 
$pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context)

# If user profile doesn't exist create new one
if ($pm.UserExists($accountName)) {
    $userProfile = $pm.GetUserProfile($accountName) 
} else  {
    $userProfile = $pm.CreateUserProfile($accountName)
# Update user profile properties
$userProfile["FirstName"].Value = "Bill"
$userProfile["LastName"].Value = "Gates"
# Commit changes

And here you have example on how to list all local users (I didn't tested it!):

share|improve this answer
New-Object : Exception calling ".ctor" with "1" argument(s): "Object reference not s et to an instance of an object." At line:8 char:17 + $pm = new-object <<<< Microsoft.Office.Server.UserProfiles.UserProfileManager($co ntext) + CategoryInfo : InvalidOperation: (:) [New-Object], MethodInvocationE xception + FullyQualifiedErrorId : ConstructorInvokedThrowException,Microsoft.PowerShell .Commands.NewObjectCommand getting error .......seems i am not able to get the object of $pm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($context) – Monica Jagani Sep 23 '11 at 12:35
Check $site and $context objects before creating $pm - are they ok? Also check if your user have permissions on User Profile Service Application – Vedran Rasol Sep 23 '11 at 12:40
can you tell me how to check for permission in User Profile Service application. I tried : “Central Administration > Manage Service Applications” > User Profile Service Application and click “Administrators” in the ribbon and assign Full control permission to the login user. – Monica Jagani Sep 26 '11 at 3:56
also click/check Permissions in the ribbon at same location – Vedran Rasol Sep 26 '11 at 7:57
thanks. working as required :) – Monica Jagani Sep 26 '11 at 12:29

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.