locked
Best way to Add/Manage lots of custom Profile Properties RRS feed

  • Question

  • Hello,

    I was wondering if anyone had suggestions (based on experience) of the best way to handle adding custom Profile Properties for a Server Farm.  Since this should be a one-time thing (I'm thinking), I guess using a Feature would not be best, or would it?  I was also looking at using a PowerShell script or Console app, etc. 

    Any suggestions?

    Thanks!

    Wednesday, September 28, 2011 3:48 PM

Answers

  • I do this with powershell.

    E.g. function below will an a profile property of type string.

    # Function to create user profile property of type string
    function CreateUserProfilePropertyString($url, $ProfileSubType, $propertyname, $propertydisplayname, $propertylength, $IsVisibleOnEditor, $IsVisibleOnViewer, $IsRequired, $DefaultPrivacy, $IsUserEditable, $AllowPolicyOverride)
    {
        $site = Get-SPSite $url;
        $context = Get-SPServiceContext($site);
                       
        #Sample to create a new custom property.
        $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($serviceContext);
        $ps = $psm.GetProfileSubtype($ProfileSubType);
        $pspm = $ps.Properties;
        $coreProp = $cpm.Create($false);
        $coreProp.Name = $propertyname;
        $coreProp.DisplayName = $propertydisplayname;
        $coreProp.Type = "string";
        $coreProp.Length = $propertylength;
        $coreProp.Commit();
        $profileTypeProp = $ptpm.Create($coreProp);
        $profileTypeProp.IsVisibleOnEditor = $IsVisibleOnEditor;
        $profileTypeProp.IsVisibleOnViewer = $IsVisibleOnViewer;
        #$profileTypeProp.IsRequired = $IsRequired;
        $profileTypeProp.Commit();
        $profileSubTypeProp = $pspm.Create($profileTypeProp);
      
        if ($DefaultPrivacy -eq "Public")
        {
            #Public
            #Privacy level gives visibility of users' profile properties, and other My Site content, to everyone.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Public;
        }
        ElseIf ($DefaultPrivacy -eq "Contacts")
        {
            #Contacts
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to my colleagues.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Contacts;   
        }
        ElseIf ($DefaultPrivacy -eq "Organization")
        {
            #Organization
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to my workgroup.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Organization;   
        }
        ElseIf ($DefaultPrivacy -eq "Manager")
        {
            #Manager
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to my manager and me.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Manager;   
        }
        ElseIf ($DefaultPrivacy -eq "Private")
        {
            #Private
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to me only.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Private;   
        }
        Else
        {
            # Default to private if privacy level is not set
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Private;   
       
        }
       
       
        $profileSubTypeProp.IsUserEditable = $IsUserEditable;
        #$profileSubTypeProp.AllowPolicyOverride = $AllowPolicyOverride;
        $profileSubTypeProp.Commit();  
        $site.Dispose();

    }

     

    • Marked as answer by sdfsda Friday, September 30, 2011 11:32 AM
    Thursday, September 29, 2011 11:31 AM
  • Hi,

    Why don't you use out of box function to create custom profile properties?

    http://technet.microsoft.com/en-us/library/cc262327.aspx

    It is quite easy to manage them and it is not one-time thing, in my opinion.

    Relevant references:

    http://msdn.microsoft.com/en-us/library/ms519896.aspx

    Regards,

    Seven

    • Marked as answer by sdfsda Friday, September 30, 2011 11:32 AM
    Friday, September 30, 2011 8:29 AM

All replies

  • I do this with powershell.

    E.g. function below will an a profile property of type string.

    # Function to create user profile property of type string
    function CreateUserProfilePropertyString($url, $ProfileSubType, $propertyname, $propertydisplayname, $propertylength, $IsVisibleOnEditor, $IsVisibleOnViewer, $IsRequired, $DefaultPrivacy, $IsUserEditable, $AllowPolicyOverride)
    {
        $site = Get-SPSite $url;
        $context = Get-SPServiceContext($site);
                       
        #Sample to create a new custom property.
        $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($serviceContext);
        $ps = $psm.GetProfileSubtype($ProfileSubType);
        $pspm = $ps.Properties;
        $coreProp = $cpm.Create($false);
        $coreProp.Name = $propertyname;
        $coreProp.DisplayName = $propertydisplayname;
        $coreProp.Type = "string";
        $coreProp.Length = $propertylength;
        $coreProp.Commit();
        $profileTypeProp = $ptpm.Create($coreProp);
        $profileTypeProp.IsVisibleOnEditor = $IsVisibleOnEditor;
        $profileTypeProp.IsVisibleOnViewer = $IsVisibleOnViewer;
        #$profileTypeProp.IsRequired = $IsRequired;
        $profileTypeProp.Commit();
        $profileSubTypeProp = $pspm.Create($profileTypeProp);
      
        if ($DefaultPrivacy -eq "Public")
        {
            #Public
            #Privacy level gives visibility of users' profile properties, and other My Site content, to everyone.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Public;
        }
        ElseIf ($DefaultPrivacy -eq "Contacts")
        {
            #Contacts
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to my colleagues.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Contacts;   
        }
        ElseIf ($DefaultPrivacy -eq "Organization")
        {
            #Organization
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to my workgroup.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Organization;   
        }
        ElseIf ($DefaultPrivacy -eq "Manager")
        {
            #Manager
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to my manager and me.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Manager;   
        }
        ElseIf ($DefaultPrivacy -eq "Private")
        {
            #Private
            #Privacy level limits the visibility of users' profile properties, and other My Site content, to me only.
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Private;   
        }
        Else
        {
            # Default to private if privacy level is not set
            $profileSubTypeProp.DefaultPrivacy = [Microsoft.Office.Server.UserProfiles.Privacy]::Private;   
       
        }
       
       
        $profileSubTypeProp.IsUserEditable = $IsUserEditable;
        #$profileSubTypeProp.AllowPolicyOverride = $AllowPolicyOverride;
        $profileSubTypeProp.Commit();  
        $site.Dispose();

    }

     

    • Marked as answer by sdfsda Friday, September 30, 2011 11:32 AM
    Thursday, September 29, 2011 11:31 AM
  • That seems like a lot of stuff, and that's just for one Property.  I have to add and manage a few dozen, including all the MeataData (some of them require custom Term Groups, etc.).  I was just wondering if anyone had a good way or tool to do this.
    Thursday, September 29, 2011 12:45 PM
  • Hi,

    Why don't you use out of box function to create custom profile properties?

    http://technet.microsoft.com/en-us/library/cc262327.aspx

    It is quite easy to manage them and it is not one-time thing, in my opinion.

    Relevant references:

    http://msdn.microsoft.com/en-us/library/ms519896.aspx

    Regards,

    Seven

    • Marked as answer by sdfsda Friday, September 30, 2011 11:32 AM
    Friday, September 30, 2011 8:29 AM
  • Seven,

    I agree, but the customer does not.  Stupid.  Wants some fully fleshed scripts or something, will only accept automation for a variety of junk that only needs to be done once and could have been done so a long time ago.

    Thanks.

    Friday, September 30, 2011 11:32 AM
  • Hi Dave,

    $psm = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($serviceContext);

    I am wondering the variable what to give in the variable $servuceContext. there its giving problem, for Interger properties the lengh would not be there,

    I am not able to execute this function. can you elaborate on all the variables you are passing? if you send some examples to cal the function would be appreciable

    thanks in advance

    Guru


    Guruprasad Marathe 

    error what I am getting here Exception calling "Get" with "1" argument(s): "Value cannot be null.

    Parameter name: serviceContext"

    Thursday, October 13, 2011 11:39 AM