共用方式為


Add / Remove Term Store Administrator and Changing Term Set Owner using PowerShell.

Many times we need to change the Term Store Administrator and Term Set owner. Reason for change could be any thing from administrator has been changed to Term store has been imported recently and it contains Administrator of other environment as Term Store Administrator.

Administrator can be changed manually but changing Administrator of Term Store and owner on all the Term Set is going to be difficult. In this scenario PowerShell can be a handy option.

For changing the Term Store Administrator, you can use the AddTermStoreAdministrator and DeleteTermStoreAdministrator method on Term Store. AddTermStoreAdministrator would not change the existing administrators and you need to remove existing administrator using DeleteTermStoreAdministrator. Both these functions take principle name as parameter. Principle name is different from display name. If you provide the display name, it won't work. If you do not know the principle name, you can get the value using PrincipleName property. For adding the administrator you can provide value in format "Domain/UserName".

For Changing the owner of term set, you can use the Owner property of term set. Name of owner can be provided in format "Domain/UserName".

Below is sample code snippet for the same. In the code, I am first removing all the existing Term Store Administrator and then adding new Term Store Administrator and then changing the owner of all Term Sets.

 $AdminName = "Domain/UserName"
$taxonomySession = Get-SPTaxonomySession -Site "Path of your site"

    $termStore = $taxonomySession.TermStores["Your Term Store Name"]

    
if($termStore -ne $null)

    {
# Removing all the existing TermStore Administrators
foreach($admin in $termStore.TermStoreAdministrators)

        {
$termStore.DeleteTermStoreAdministrator($admin.PrincipalName);

        }        



        #Adding new term Store Administrator
$termStore.AddTermStoreAdministrator($AdminName);

                 
$group = $termStore.Groups["Your Group name"]

        if($group -ne $null)

        {     

            #Updating Owner of all the term set.                    
foreach($termSet in $group.TermSets) 

            {
$termSet.Owner = $AdminName;

            }

        }

    }

           
$termStore.CommitAll();