powershell 在映射到Term Store的UPS中创建新的部分和新属性。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了powershell 在映射到Term Store的UPS中创建新的部分和新属性。相关的知识,希望对你有一定的参考价值。

# ----------------------------------------------
# Author: Romain Blanchard / Internet
# Date: 10.02.2015
# Description: Create new section and new property in UPS mapped to Term Store.
# ----------------------------------------------

# Get parameters
$mySiteWebApp = Read-Host "Please enter the MySite Web Application URL"
$termStoreSrvApp = Read-Host "Please enter the Managed Metadata Service Application name"
$userprofileSrvApp = Read-Host "Please enter the User Profile Service Application name"

# Add SharePoint DLLs
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.SharePoint")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Administration")
[void][System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Sharepoint.Taxonomy")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server")
[System.Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Server.UserProfiles")

# Get site collection for MySite
$sitecollection = Get-SPSite | Where-Object {$_.Url -eq $mySiteWebApp}
if($sitecollection -ne $null)
{

    # Get the taxonomy session
    $taxSession = Get-SPTaxonomySession -site $sitecollection

    $termStore = $taxSession.TermStores[$termStoreSrvApp]

    if($termStore -ne $null) 
    {

        # Get the term store group's name
        $termStoreGroup = $termStore.Groups["Référentiels RBLA"]

        # Get the term set
        $termSetExpertise = $termStoreGroup.TermSets["Expertise"]

        # Get the user profile app
        $serviceApplication = Get-SPServiceApplication | ?{$_.TypeName -eq $userprofileSrvApp}
        $serviceContext = [Microsoft.SharePoint.SPServiceContext]::GetContext($serviceApplication.ServiceApplicationProxyGroup, [Microsoft.SharePoint.SPSiteSubscriptionIdentifier]::Default)
        $userProfileConfigManager = New-Object Microsoft.Office.Server.UserProfiles.UserProfileConfigManager $serviceContext
        $userProfilePropertyManager = $userProfileConfigManager.ProfilePropertyManager
        $userProfileTypeProperties = $userProfilePropertyManager.GetProfileTypeProperties([Microsoft.Office.Server.UserProfiles.ProfileType]::User)
        $userProfileSubTypeManager = [Microsoft.Office.Server.UserProfiles.ProfileSubTypeManager]::Get($serviceContext)
        $userProfile = $userProfileSubTypeManager.GetProfileSubtype([Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName([Microsoft.Office.Server.UserProfiles.ProfileType]::User))
        $userProfileProperties = $userProfile.Properties
        $ps = $userProfileSubTypeManager.GetProfileSubtype([Microsoft.Office.Server.UserProfiles.ProfileSubtypeManager]::GetDefaultProfileName([Microsoft.Office.Server.UserProfiles.ProfileType]::User))
        $pspm = $ps.Properties

        #Create new section in User Profiles
        Write-Host "Creating new section for 'RBLA'...."
        $allEntries = $userProfileConfigManager.GetPropertiesWithSection();

        $sectionExists =$false

        foreach ($temp in $allEntries) 
        {
            if($temp.Name -eq "RBLA") 
            {
                Write-Host "Section for 'RBLA' already exists.";
                $sectionExists = $true;
                $section = $temp
            }
        }

        if ($sectionExists -ne $true)
        {
            $section = $allEntries.Create($true);
            $section.Name = "RBLA";
            $section.ChoiceType = [Microsoft.Office.Server.UserProfiles.ChoiceTypes]::Off;
            $section.DisplayName = "RBLA"
            $section.Commit();
            Write-Host "Section 'RBLA' created"
        }

        Write-Host "Creating new properties...."

        $Privacy = "public"
        $PrivacyPolicy = "OptIn"

        $coreProperties = $userProfilePropertyManager.GetCoreProperties()

        # Setting Custom Properties below, amend names as you did above to match your fields

        # Set new Custom Property for "Expertise"
        $PropertyName = "RBLAExpertise"
        $PropertyDisplayName = "Expertise"
        $newProperty = $coreProperties.Create($false)
        $newProperty.Name = $PropertyName
        $newProperty.DisplayName = $PropertyDisplayName
        $newProperty.Type = "string"
        $newProperty.Length = "50"
        $newProperty.IsMultivalued = $true
        $newProperty.TermSet = $termSetExpertise

        # Add the new property
        $coreProperties.Add($newProperty)
        $profileTypeProp = $userProfileTypeProperties.Create($newProperty)
        $profileTypeProp.IsVisibleOnEditor = $true
        $profileTypeProp.IsVisibleOnViewer = $true
        $userProfileTypeProperties.Add($profileTypeProp)

        $profileSubTypeProp = $pspm.Create($profileTypeProp);
        $profileSubTypeProp.IsUserEditable = $true
        $profileSubTypeProp.DefaultPrivacy = $Privacy
        $profileSubTypeProp.AllowPolicyOverride

        $pspm.Add($profileSubTypeProp);

        Write-Host "Completed"
    } 
    else
    {
        #Termstore not found
        Write-Host "Unable to connect to term store"
    }
} 
else
{
    Write-Host "Unable to connect to MySite Web Application"
}

以上是关于powershell 在映射到Term Store的UPS中创建新的部分和新属性。的主要内容,如果未能解决你的问题,请参考以下文章

使用 powershell 创建 AWS Parameter Store 键/值对

[SF] The term 'Add-AzServiceFabricClusterCertificate' is not recognized as the name of a cmd

识别 iPhone 用户 iTunes Store 区域?

Powershell Array Strings - 在 SSIS 中映射不同的变量参数名称

Elasticsearch之Doc Value与Fielddata

git,es的基本查询,组合查询,mapping映射,i分词,term和match