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.

1 Answer 1


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!):

  • 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) Sep 23, 2011 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 Sep 23, 2011 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. Sep 26, 2011 at 3:56
  • also click/check Permissions in the ribbon at same location Sep 26, 2011 at 7:57
  • Good! If you find my answer to be helpful please take time to upvote it and/or accept it as an answer FAQ Sep 26, 2011 at 12:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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