0

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
}
}

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.

Plexus81
  • 1,221
  • 6
  • 23
  • 44

1 Answers1

1

One item that jumps out is that you're disposing of your SPSite object before your code has opportunity to make use of it. Move ' $site.Dispose(); ' to the end of your code block.

sqlsolver
  • 91
  • 4
  • The solution work with standard user profile properties, but NOT with custom properties. So I don't think that $site.Dispose() is the problem – Plexus81 Feb 19 '15 at 11:15