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:
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-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.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:
Output: And in the Central Administration you could see the newly created custom properties in Custom properties section.