top of page
Writer's pictureVijai Anand Ramalingam

Create User Profile Sub-Types in SharePoint 2010 using Powershell

In this article you will see how to create User Profile Sub-Types in SharePoint 2010 using powershell.

User Profile Sub-Types:

User properties can be associated to the particular user Profile Sub Type and these sub types allows creating different kinds of User Profiles. Each User Profiles will display different user properties based on the Sub Types. In this you will see how to create User Profile sub types in SharePoint 2010 using powershell.

Steps Involved:

  1. Create the input xml file which contains the inputs for creating User Profile Sub Types.

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


CreateUserProfileSubtypes.xml

<?xml version="1.0" encoding="utf-8" ?> <ProfileSubtype> <SiteURL>http://servername/hrp/hrp/</SiteURL> <Subtype Name="HR" DisplayName="HR Subtype" ></Subtype> <Subtype Name="RND" DisplayName="RND Subtype" ></Subtype> </ProfileSubtype >

CreateUserProfileSubtypes.ps1

#----------------Get the xml file---------------------------------------------------------------

[xml]$xmlData=Get-Content "D:\VijaiPOC\CreateUserProfileSubtypes.xml"

#----------------Create new user Profile Subtypes----------------------------------------------------

function CreateUserProfileSubtypes() {      $site = Get-SPSite $xmlData.ProfileSubtype.siteURL $context = Get-SPServiceContext($site)   $psm = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($context) $xmlData.ProfileSubtype.Subtype | ForEach-Object{ $subtype=$psm.GetProfileSubtype($_.Name) if($subtype -eq $null)                { $psm.CreateSubType($_.Name,$_.DisplayName,[Microsoft.Office.Server.UserProfiles.ProfileType]::User) write-host -f green $_.DisplayName " is created successfully"                } else                { write-host -f yellow $subtype.DisplayName " already exists"                }               } $site.Dispose()          }

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

CreateUserProfileSubtypes


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 as Administrator.

  5. Run the D:\VijaiPOC\CreateUserProfileSubtypes.ps1


Summary:

Thus in this article you have seen how to create User Profile Sub-types using Powershell.

0 comments

Comments


bottom of page