Create User Profile MultiValue Properties in SharePoint 2010 using PowerShell


Create User Profile Properties in SharePoint 2010

User Profile properties are used to describe personal information about the user. The IsMultiValued parameter in the object model indicates whether the property is a multivalue property or not. However, just like the property data type, this parameter is not modifiable, once it is set.

We can to create User Profile MultiValue Properties in SharePoint 2010 from Central Administration.

Go to Central Administration - Application Management - Manage Service Applications - User Profile Service Application.

sharepoint 2010
Click on Manage User Properties

Manage User Properties in sharepoint

Click on New Property link to create a new custom user profile property.

profile property in sharepoint 2010

sharepoint profile property

Multivalue Separator:

Multivalue Separator in sharepoint

Note: For more information on Multivalue Separator please refer http://msdn.microsoft.com/en-us/library/microsoft.office.server.userprofiles.multivalueseparator.aspx.

Automation: Create User Profile Multivalue Properties in SharePoint 2010 using PowerShell

Here we will be seeing how to create the User Profile Multivalue Properties in SharePoint 2010 using PowerShell.

Steps Involved:

  1. Create the input XML file which contains the inputs for creating User Profile Multivalue properties.

  2. Create ps1 file which contains the script for creating User Profile Multivalue properties.


CreateUserProfileMultivalueProperties.xml

<?xml version="1.0" encoding="utf-8" ?>
<UserProfileMultivalueProperties>
  <
SiteURL>http://serverName:8080/</SiteURL
  <Property Name="CustomMultivalue1" DisplayName="CustomMultivalue1" Length="25" Privacy="Contacts" PrivacyPolicy="mandatory"
IsVisibleOnEditor="$true" IsVisibleOnViewer="$true" IsMultivalued="$true" Separator="Comma"></Property
>
  <Property Name="CustomMultivalue2" DisplayName="CustomMultivalue2" Length="25" Privacy="Contacts" PrivacyPolicy="mandatory"
IsVisibleOnEditor="$true" IsVisibleOnViewer="$true" IsMultivalued="$true" Separator="Comma"></Property
>
  <Property Name="CustomMultivalue3" DisplayName="CustomMultivalue3" Length="25" Privacy="Contacts" PrivacyPolicy="mandatory"
IsVisibleOnEditor="$true" IsVisibleOnViewer="$true" IsMultivalued="$true" Separator="Comma"></Property
>
  <Property Name="CustomMultivalue4" DisplayName="CustomMultivalue4" Length="25" Privacy="Contacts" PrivacyPolicy="mandatory"
IsVisibleOnEditor="$true" IsVisibleOnViewer="$true" IsMultivalued="$true" Separator="Comma"></Property

</UserProfileMultivalueProperties>

CreateUserProfileMultivalueProperties.ps1

#----------------Get the xml file---------------------------------------------------------------
 
 [
xml]$xmlData=Get-Content "C:\Users\Desktop\ContentSources\CreateUserProfileMultivalueProperties.xml" 
 
#----------------Create new custom User Profile Multivalue properties---------------------------------------------
function CreateUserProfileMultivalueProperties()
{    
     
$site = Get-SPSite $xmlData.UserProfileMultivalueProperties.SiteURL
     
$context = Get-SPServiceContext($site)
     
$upcm = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager($context);     
     
$ppm = $upcm.ProfilePropertyManager
     
$cpm = $ppm.GetCoreProperties()
     
$ptpm = $ppm.GetProfileTypeProperties([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
     
$psm = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($context)
     
$ps = $psm.GetProfileSubtype([Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName
[Microsoft.Office.Server.UserProfiles.ProfileType]::User))
     
$pspm = $ps.Properties
     
$xmlData.UserProfileMultivalueProperties.Property | ForEach-Object{
         
$property = $pspm.GetPropertyByName($_.Name)           
           
if($property -eq $null)
            {
               
$Privacy=$_.Privacy
               
$PrivacyPolicy=$_.PrivacyPolicy
                 
$Separator=$_.Separator
               
$coreProp = $cpm.Create($false)
               
$coreProp.Name = $_.Name
               
$coreProp.DisplayName = $_.DisplayName
               
$coreProp.Type = [Microsoft.Office.Server.UserProfiles.PropertyDataType]::StringMultiValue
                 
$coreProp.Separator=[Microsoft.Office.Server.UserProfiles.MultiValueSeparator]::$Separator
                $coreProp.IsMultivalued=$_.IsMultivalued
               
$coreProp.Length = $_.Length
               
$cpm.Add($coreProp)
               
$profileTypeProp = $ptpm.Create($coreProp);
               
$profileTypeProp.IsVisibleOnEditor = $true;
               
$profileTypeProp.IsVisibleOnViewer = $true;
               
$ptpm.Add($profileTypeProp)
               
$profileSubTypeProp = $pspm.Create($profileTypeProp);
               
$profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::$Privacy
                $profileSubTypeProp.PrivacyPolicy = [Microsoft.Office.Server.UserProfiles.PrivacyPolicy]::$PrivacyPolicy         
               
$pspm.Add($profileSubTypeProp)
                 
write-host -f green $_.Name multivalue property is created successfully            
            }
           
else
            {
              
write-host -f green $_.Name multivalue property is created successfully   
            }
      }
}

#----------------Calling the function---------------------------------------------
 CreateUserProfileMultivalueProperties

CreateUserProfileMultivalueProperties

Run the Script:

  1. Go to Start.
  2. Click on All Programs.
  3. Click on Microsoft SharePoint 2010 Products and then click on SharePoint 2010 Management Shell.
  4. Run the C:\Users\Desktop\ContentSources\CreateUserProfileMultivalueProperties.ps1

Output:

sharepoint with powershell

And in the Central Administration you could see the newly created custom multivalue properties in Custom properties section.

multivalue properties in sharepoint

Up Next
    Ebook Download
    View all
    Learn
    View all