top of page
Writer's pictureVijai Anand Ramalingam

Create User Profile 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. We can to create User Profile Properties in SharePoint 2010 from Central Administration.

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


  • Click on Manage User Properties


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


Automation: Create User Profile Properties in SharePoint 2010 using PowerShell

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

Steps Involved:

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

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


CreateUserProfileProperties.xml

<?xml version="1.0" encoding="utf-8" ?> <UserProfileProperties>   <SiteURL>http://serverName:8080/</SiteURL>    <Property Name="Custom1" DisplayName="Custom1" Type="string" Length="25"Privacy="Contacts" PrivacyPolicy="mandatory" IsVisibleOnEditor="$true" IsVisibleOnViewer="$true"></Property>   <Property Name="Custom2" DisplayName="Custom2" Type="string" Length="25"Privacy="Contacts" PrivacyPolicy="mandatory" IsVisibleOnEditor="$true" IsVisibleOnViewer="$true"></Property>   <Property Name="Custom3" DisplayName="Custom3" Type="string" Length="25"Privacy="Contacts" PrivacyPolicy="mandatory" IsVisibleOnEditor="$true" IsVisibleOnViewer="$true"></Property>   <Property Name="Custom4" DisplayName="Custom4" Type="string" Length="25"Privacy="Contacts" PrivacyPolicy="mandatory" IsVisibleOnEditor="$true" IsVisibleOnViewer="$true"></Property>  </UserProfileProperties> CreateUserProfileProperties.ps1

#----------------Get the xml file---------------------------------------------------------------  [xml]$xmlData=Get-Content"C:\Users\Desktop\ContentSources\CreateUserProfileProperties.xml"

#----------------Create new custom User Profile properties--------------------------------------------- function CreateUserProfileProperties() {     $site = Get-SPSite $xmlData.UserProfileProperties.SiteURL $context = Get-SPServiceContext($site) $upcm = New-ObjectMicrosoft.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.UserProfileProperties.Property | ForEach-Object{ $property = $pspm.GetPropertyByName($_.Name)          if($property -eq $null)             { $Privacy=$_.Privacy $PrivacyPolicy=$_.PrivacyPolicy $coreProp = $cpm.Create($false) $coreProp.Name = $_.Name $coreProp.DisplayName = $_.DisplayName $coreProp.Type = $_.Type $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 yellow $_.Name property is created successfully             } else             { write-host -f yellow $_.Name property already exists             }       } } #----------------Calling the function--------------------------------------------- CreateUserProfileProperties

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 theC:\Users\Desktop\ContentSources\CreateUserProfileProperties.ps1


Output:


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


0 comments

Comments


bottom of page