I am using SP2013 on-premise standard edition and we tried to update the user profile with a PowerShell script. Unfortately, part of profiles cannot be updated. The exception is "There is already a term with the same default label and parent term".
The update field is a custom field named CustBusinesUnit (String - single value). The field is bind to a custom termset CustBusinesUnit. The field's value is not coming from AD sync. The value is updated by PowerShell half year ago. It was updated successfully. However, when we update again today exception is threw.
I have no idea what the error message mean and how to get around it. Is it means the new value is same as old value? The PowerShell read a CSV in UTF8 format. Most of the content are in Chinese.
I tried to reproduce in a test environment but not success reproduce. In my test environment, if I update 'CustBusinesUnit' field with a value not exist in 'CustBusinesUnit' termset, it will auto create a new term. Otherwise, it will auto match 'CustBusinesUnit' field with the existing term in 'CustBusinesUnit' termset. Whatever I tried the update go smooth. It never return exception. The problem only exist in production environment and the titled error is the only hint.
I understand it is a rare case. Any brainstorming is welcome. Thanks.
Here is part of PowerShell (it may contains syntax error because I cut off some sensitive information):
$userDetails = Import-Csv -Path $csv
$upProperties = "SPS-PhoneticDisplayName","StaffID","Title","CustCompany","CustBusinessUnit","Manager","Assistant","SPS-Location","WorkPhone","CellPhone","CustDepartment"
foreach ($user in $userDetails){
if ($upm.UserExists($user.AccountName))
{
try {
$profileproperty = $upm.GetUserProfile($user.AccountName)
$upProperties | foreach-object {
if ($user.$_ -ne $null) {
if ($profileproperty[$_].Value -eq $user.$_ -or ($profileproperty[$_].Value -eq $null -and $user.$_ -eq '')) {
# don't update
} else {
$profileproperty[$_].Value = $user.$_
$profileproperty.Commit()
}
}
}
} catch [System.Exception]{
$ErrorMessage = $_.Exception.Message
# log down the message somewhere.
}
}
Addition information: I found some of the terms in CustBusinessUnit are being marked as "reuse term". I tested in my test farm and cannot reproduce error due to "reuse term"
PowerShell
, While updating profiles one of theProperties
i.e.CustBusinesUnit
which is custom and bound to aTermSet - CustBusinesUnit
throws an error. Correct me if I am wrong. Also if possible share your code.