Reputation: 1251
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.
Upvotes: 0
Views: 1335
Reputation: 91
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.
Upvotes: 1