1

Having problem updating custom user profile properties. Anyone with the same problem, code below:

[void][reflection.assembly]::Loadwithpartialname("Microsoft.Office.Server");            
$site=new-object Microsoft.SharePoint.SPSite("$ProfilFullURL");            
$serviceContext = Get-SPServiceContext $site;            
$site.Dispose();            
$upm = new-object Microsoft.Office.Server.UserProfiles.UserProfileManager($serviceContext);

function Update-UserProfileProperty ($property, $excelProperty)
{
Write-Host "Setting property $property : " -NoNewline
Try
{       
    $userProfile["$property"].Value = $excelProperty;            
    $userProfile.Commit()
    Write-Host "$excelProperty" -ForegroundColor Green
}
Catch [system.exception]
{
    Write-Host "Error" -ForegroundColor Red
}
}

Foreach ($user in $userobjects) 
{
    $userProfile = Get-UserProfileProperties $user
}

function Get-UserProfileProperties ($user)
{ 
   $userName = $user.SM_LoginName
Write-Host "$userName : Finding user profile ..." -NoNewline
Try
{       
     $userProfile = $upm.GetUserProfile("$userName")
     Write-Host "Found" -ForegroundColor Green
     UserProfileProperty $user

}
Catch [system.exception]
{
    Write-Host "Not found" -ForegroundColor Red
    return
}
return $userProfile
}

What I'm trying to do is to add migrate data from a excel spreadsheet into the custom user profile property. The user and property exist!

The code works with standard properties like FirstName etc.

UPDATE The error I got is

The property 'Value' cannot be found on this object. Verify that the property exists and can be set. At line:1 char:1 + $userProfile[$property].Value = $excelProperty + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : PropertyNotFound

Got this error ONLY on custom user properties

6
  • "Having problem" / "Anyone with the same problem": What kind of problem do you have exactly? An exception (at which line?) or the property simlpy was not updated?
    – pholpar
    Commented Feb 18, 2015 at 20:08
  • The problem is that standard user properties can be set by the code. But custom user properties do not!
    – Plexus81
    Commented Feb 18, 2015 at 20:12
  • Do you have an error (catched exception in code)? If you dump out the profile properties ($upm.Properties | % { $_.Name }), is the name you use in the list?
    – pholpar
    Commented Feb 18, 2015 at 20:52
  • Yes the property is listed .. But it dosent want to be set..
    – Plexus81
    Commented Feb 18, 2015 at 21:20
  • 2
    Yes, it should work. Personally, I don't use the syntax $userProfile["$property"], instead without the quotes like $userProfile[$property], but it should not make a difference, AFAIK. What I don't see in your code, where the $userProfile variable in the Update-UserProfileProperty method was defined. What is the type of your custom propety? String / date / integer, etc.?
    – pholpar
    Commented Feb 18, 2015 at 21:36

1 Answer 1

1

Yes, it should work. Personally, I don't use the syntax $userProfile["$property"], instead without the quotes like $userProfile[$property], but it should not make a difference, AFAIK. What I don't see in your code, where the $userProfile variable in the Update-UserProfileProperty method was defined. What is the type of your custom property? String / date / integer, etc.?

Please, ensure that you do use the right data type!

Your Answer

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

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