About Me

Having 12 years experience in Microsoft technologies.Since more than 7 years working in SharePoint technologies. Expert in providing consultation for SharePoint projects. Hands on with development and administration.
Showing posts with label managed meta data. Show all posts
Showing posts with label managed meta data. Show all posts

Monday, 25 August 2014

Powershell Script - Create custom user profile properties in SharePoint 2013

The powershell script will create custom user profile properties by reading data from xml configuration file. The script accepts following input parameters

1. SiteUrl - Site colletion url
2. ManagedMetaDataServiceName - MMS service app name

Points to be noted

1. The MMS service is required, as one of the custom property gets data from predefined term set.
2. We need xml file which has required configuration.

Steps involved

1. Save following as xml file format, you can add as many as configurations you want and save as costumUserProfileProperties.xml and should be in the root directory of the script where you are running...

<?xml version="1.0" encoding="utf-8" ?>
<UserProfileProperties>
 
<Property Name="SkillSets" DisplayName="SkillSets" Type="string (Multi Value)"  IsTaxonomic="True" TermSet="Skills" Length="500" Privacy="Public" PrivacyPolicy="mandatory" IsVisibleOnEditor="$true"
IsVisibleOnViewer="$true"  IsUserEditable ="$true"></Property>

<Property Name="Interests" DisplayName="Interests" Type="string (Multi Value)"  IsTaxonomic="True" TermSet="Skills" Length="500" Privacy="Public" PrivacyPolicy="mandatory" IsVisibleOnEditor="$true"
IsVisibleOnViewer="$true"  IsUserEditable ="$true"></Property>

</UserProfileProperties>

   

2. Save following script as psCreateCustomUserProfileProperty.ps1
#-----------------------------------------------------------------------------
# Name:             psCreateCustomUserProfileProperty.ps1 
# Description:      This script will create termset names as 'Skills'
#                    and creates following user profile properties
#                   'Skills' & 'Interests'
#                    
# Usage:            Run the script by passing the paramter $SiteUrl,
#                   ManagedMetaDataServiceName
# Created By:       Vamsi Mohan Mitta
# Date:             01/07/2014
#-----------------------------------------------------------------------------

Param([Parameter(Mandatory=$true)]
      [String]
      $SiteUrl,
      [Parameter(Mandatory=$true)]
      [String]
      $ManagedMetaDataServiceName     
)

if ((gsnp Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null){
    asnp Microsoft.SharePoint.Powershell
}
#Do not modify anything in the script from here onwards
function Get-ScriptDirectory
{
 $Invocation = (Get-Variable MyInvocation -Scope 1).Value
 Split-Path $Invocation.MyCommand.Path
}

#Get Current Physical Path
$currentPhysicalPath = Get-ScriptDirectory

$logfile=$currentPhysicalPath + "\log.log"

Start-Transcript $logfile

#Connect to the Metadata Service
$taxSite = get-SPSite $SiteUrl    # Central Admin URL  
$taxonomySession = Get-SPTaxonomySession -site $taxSite
$termStore = $taxonomySession.TermStores[$ManagedMetaDataServiceName]    # Meata data service name
write-host “Connection made with term store -” $termStore.Name -ForegroundColor Green

$termGroupName = "ECTermGroup"
#Create a group
      if ($termStore.Groups[$termGroupName] -eq $null)
      {
        $termGroup = $termStore.CreateGroup($termGroupName)
        $termStore.CommitAll()
        write-host “Successfully created term group -” $termGroupName -ForegroundColor Green
      }
      else
      { write-host “Term Group already -” $termGroupName " exists" -ForegroundColor Blue }

#Connect to existing term group
$termGroup = $termstore.groups[$termGroupName];

#TERM SETS
#Create a term set

    if($termGroup.TermSets["Skills"] -eq $null)
    {
    $createTermSet = $termGroup.CreateTermSet("Skills")
    $termStore.CommitAll()
    write-host “Successfully created term set” -ForegroundColor Green
    }
    else
      { write-host “Term Set already exists" -ForegroundColor Blue }


#Connect to existing term set
$termset = $termGroup.Termsets["Skills"]

$term = $termSet.CreateTerm("Sea wall",1033)
$term.SetDescription(“Sea wall”, 1033)
$term.CreateLabel("Seawall”, 1033, $false)

$term = $termSet.CreateTerm("Tunnels and bridges",1033)
$term.SetDescription(“Tunnels and bridges”, 1033)
$term.CreateLabel("Tunnelsandbridges”, 1033, $false)


$term = $termSet.CreateTerm("Water pipelines",1033)
$term.SetDescription(“Water pipelines”, 1033)
$term.CreateLabel("Waterpipelines”, 1033, $false)

$term = $termSet.CreateTerm("Desalination plants- Land reclamation",1033)
$term.SetDescription(“Desalination plants- Land reclamation”, 1033)
$term.CreateLabel("Desalinationplants”, 1033, $false)

$TermSet.IsOpenForTermCreation = $true;

# Contribute permission on term group
$user = "c:0(.s|true"
$termGroup.AddContributor($user)


$termStore.CommitAll()

#----------------This service application is the default storage location for column specific term sets---------------------------------------------------------------


# This service application is the default storage location for column specific term sets.  on proxy peroperty select this
# Get Metadata service application proxy
$metadataserviceapplicationname = $ManagedMetaDataServiceName
Set-SPMetadataServiceApplicationProxy -Identity $metadataserviceapplicationname -DefaultSiteCollectionTaxonomy:$true

#$metadataserviceapplicationproxy = get-spmetadataserviceapplicationproxy $metadataserviceapplicationname
#$metadataserviceapplicationproxy.Properties["IsDefaultSiteCollectionTaxonomy"] = $true

# Create a custom property with above term set as input.

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

 #[xml]$xmlData=Get-Content $xmlFilePath

 $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
 $filenamne = $scriptPath + '\' + "costumUserProfileProperties.xml"
 [xml]$xmlData=Get-Content $filenamne

#----------------Create new custom User Profile properties---------------------------------------------
Add-PsSnapin Microsoft.SharePoint.PowerShell -ErrorVariable err -ErrorAction SilentlyContinue

[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")

function CreateUserProfileProperties($SiteUrl,$ManagedMetaDataServiceName)
{    
     
#Connect to the Metadata Service
$taxSite = get-SPSite $SiteUrl  
$taxonomySession = Get-SPTaxonomySession -site $taxSite
$termStore = $taxonomySession.TermStores[$ManagedMetaDataServiceName]

#Connect to existing term group
$termGroup = $termstore.groups["ECTermGroup"];
$termSetSkill = $termGroup.TermSets["Skills"]


      #$site = Get-SPSite $xmlData.UserProfileProperties.SiteURL
      $site = Get-SPSite $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
                 #$coreProp.IsTaxonomic=[Microsoft.SharePoint.Taxonomy.TermSet]$_.IsTaxonomic

                 $coreProp.TermSet=$termSetSkill

                $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
                $profileSubTypeProp.IsUserEditable = $true;  
                $profileSubTypeProp.AllowPolicyOverride        
               
                $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 -SiteUrl $SiteUrl -ManagedMetaDataServiceName $ManagedMetaDataServiceName

 Stop-Transcript
 Echo Finish


Step2: Create batch file to run the script. Save file in .bat format.

cd /d %~dp0
powershell -file  ./psCreateCustomUserProfileProperty.ps1 -SiteUrl "xxxxx" -ManagedMetaDataServiceName "MMS_Proxy"
pause

Happy powershell coding... please feel free to comment...

Friday, 4 July 2014

Powershell Script - Create Term Sets & groups in SharePoint 2013 Managed Meta Data service

The following script will create various term set groups, term sets & terms. GUID is optional. The script will create log file to current directory where the script runs... This script will create two term groups & one term set for each respective group.

Steps involved

1. Save following script as psCreateTermSets.ps1


#-----------------------------------------------------------------------------
# Name:             psCreateTermSets.ps1 
# Description:      This script will create a list of termset groups,termsets,
#                    terms along with guids.
#                    
# Usage:            Run the script by passing the paramter SiteUrl,
#                   ManagedMetaDataServiceName
# Created By:       Vamsi Mohan Mitta
#-----------------------------------------------------------------------------

Param([Parameter(Mandatory=$true)]
      [String]
      $SiteUrl,
      [Parameter(Mandatory=$true)]
      [String]
      $ManagedMetaDataServiceName
)

if ((gsnp Microsoft.SharePoint.Powershell -ErrorAction SilentlyContinue) -eq $null){
    asnp Microsoft.SharePoint.Powershell
}

function Get-ScriptDirectory
{
 $Invocation = (Get-Variable MyInvocation -Scope 1).Value
 Split-Path $Invocation.MyCommand.Path
}

# Create term groups with guid
Function CreateTermGroup($termStore, $termGroupName, $GUID)
 {
     if ($termStore.Groups[$termGroupName] -eq $null)
      {
        $termGroup = $termStore.CreateGroup($termGroupName, $GUID)
        $termStore.CommitAll()
        write-host “Successfully created term group -” $termGroupName -ForegroundColor Green
      }
      else
      { write-host “Term Group already -” $termGroupName " exists" -ForegroundColor Blue }
  }


 Function CreateTermSets($termGroup, $termSet, $termSetGuid)
 {   
    $getTermGroup = $termStore.Groups[$termGroup]
    if($getTermGroup.TermSets[$termSet] -eq $null)
    {
    $createTermSet = $getTermGroup.CreateTermSet($termSet,[System.Guid]($termSetGuid))
    $termStore.CommitAll()
    write-host “Successfully created term set-” $termSet -ForegroundColor Green
    }
    else
      { write-host “Term Set already -” $termSet " exists" -ForegroundColor Blue }
 }

 #Get Current Physical Path
$currentPhysicalPath = Get-ScriptDirectory

$logfile=$currentPhysicalPath + "\log.log"

Start-Transcript $logfile

 #declare all respective term groups, term sets & their guids
 $grpConstructionProject = "Construction Project"
 $guidConsProject = "14a7dfbc-d818-46f4-afbc-578fe1fe65df"

 $grpITProject = "IT Project"
 $guidITProject = "f3036492-1f65-46ba-ba69-4b0b2272ca35"

 $termSetConsClient = "Client"
 $guidConsClient = "19a01208-e1e3-49be-9f8d-fdebcbf9fb83"

 $termSetConsIndustry = "Industry & sector"
 $guidConsIndustry = "2FC48649-FF10-4A2E-BF72-6C600EA3E1AF"

 $termSetITClient = "Client"
 $guidITClient = "32088415-f136-42da-af43-9bcc360e5a34"

 $termSetITIndustry = "Industry"
 $guidITIndustry = "d6f66023-3e31-48ab-b413-64a6cdbca1b2"

 $termSetITSubIndustry = "Sub-Industry"
 $guidITSubIndustry = "87567d4f-69fc-4259-82c7-88042d880b58"

 $termSetITTechnology = "Technology"
 $guidITTechnology = "9f18bc77-3d82-4816-8f02-569cb041a6b6"


$taxonomySite = get-SPSite $SiteUrl
#Connect to Term Store in the Managed Metadata Service Application
 $taxonomySession = Get-SPTaxonomySession -site $taxonomySite
 $termStore = $taxonomySession.TermStores[$ManagedMetaDataServiceName]
 write-host “Connection made with term store -” $termStore.Name -ForegroundColor Green

 #create term groups
 CreateTermGroup -termStore  $termStore -termGroupName $grpConstructionProject -GUID $guidConsProject
 CreateTermGroup -termStore  $termStore -termGroupName $grpITProject -GUID $guidITProject

 #Create term sets
 CreateTermSets -termGroup $grpConstructionProject -termSet $termSetConsClient -termSetGuid $guidConsClient
 CreateTermSets -termGroup $grpITProject -termSet $termSetITClient -termSetGuid $guidITClient
 
   #Create terms for construction project - Client
    $getTermGroup = $termStore.Groups[$grpConstructionProject]
    $getTermSet = $getTermGroup.TermSets[$termSetConsClient]
    $getTermSet.CreateTerm("Apple Corp",1033)
    $getTermSet.CreateTerm("Commonwealth Bank",1033)
    $getTermSet.CreateTerm("Energy Australia",1033)
    $getTermSet.CreateTerm("Government of South Australia",1033)
    $getTermSet.CreateTerm("Sony Music",1033)
    $termStore.CommitAll()
    write-host “Successfully created terms for term set-” $termSetConsClient -ForegroundColor Green
   
    #Create terms for IT project - Client
    $getTermGroup2 = $termStore.Groups[$grpITProject]
    $getTermSet2 = $getTermGroup2.TermSets[$termSetITClient]
    $getTermSet2.CreateTerm("AGL",1033)
    $getTermSet2.CreateTerm("CUG",1033)
    $getTermSet2.CreateTerm("Commonwealth Bank",1033)      
    $termStore.CommitAll()
    write-host “Successfully created terms for term set-” $termSetITClient -ForegroundColor Green

        Stop-Transcript
    Echo Finish

--------------------------------------------------------------------------------------------------------------------------
Step2: Create batch file to run the script. Save file in .bat format.

cd /d %~dp0
powershell -file  ./psCreateTermSets.ps1 -SiteUrl "https://xxxx..com" -ManagedMetaDataServiceName "MMS_Proxy"
pause


Happy powershell coding... please feel free to comment...

- vamsi



Sunday, 7 April 2013

Managed Metadata Column Limitations - SP 2010

Hi All,
As everybody thinks that, SharePoint 2010 managed meta data column is very handy and useful for our all list operations and other SPD changes. However, following are limitations about Managed Meta Data column in SP 2010.
Briefly,
1) No InfoPath Support
2) No SharePoint Workspace Support
3) No Support in Office 2007
4) Cannot Edit Managed Metadata values in Datasheet Mode
5) Limitations in Views
6) Extra care required in SharePoint Designer Workflows
7) Feature deployment of Managed Metadata requires care
8 ) Cannot be used in calculated fields
9) Maximum of 250 terms selected per Managed Metadata Column
10) Caution when restoring a Local Term Set to another Content Database
11) Taxonomy feature is not activated on the Blank Site Template
12) Know capacity boundaries
13) Cannot add a Managed Metadata Column through SharePoint Designer
 
I referred following blog, and check below url for detailed explanation about each point mentioned from above list.
http://www.sharepointanalysthq.com/2011/06/managed-metadata-column-limitations/