使用 PowerShell 在 SharePoint 2016 中创建托管元数据服务应用程序 (MMS)
托管元数据服务使我们能够集中管理企业级元数据和内容类型,以便在网站集、Web 应用程序甚至跨农场之间使用。 SharePoint 2016 中托管元数据服务的创建为我们提供了“术语库”,它是管理术语的中央存储库。术语库允许管理员添加/更新/删除术语集、术语组和术语。
使用以下 PowerShell 脚本在 SharePoint 2016 中添加新的托管元数据服务应用程序。相应地更改配置参数值,例如:服务应用程序名称、应用程序池、数据库名称等。
先决条件:在创建托管元数据服务应用程序之前创建内容类型中心。请参阅:在 SharePoint 2013 中创建内容类型中心
用于在 SharePoint 2016 中创建托管元数据服务应用程序的 PowerShell 脚本:
Add-PSSnapin Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue
#Configuration Parameters
$ServiceAppName = "Managed Metadata Service Application"
$ServiceAppProxyName = "Managed Metadata Service Application Proxy"
$AppPoolAccount = "Crescent\SP16-AppPool"
$AppPoolName = "Service Application App Pool"
$DatabaseServer ="SP16-SQL001"
$DatabaseName = "SP16_Service_MMS"
$ContentTypeHub="https://intranet.crescent.com/ctypehub"
Try {
#Set the Error Action
$ErrorActionPreference = "Stop"
#Check if Managed account is registered already
Write-Host -ForegroundColor Yellow "Checking if the Managed Accounts already exists"
$AppPoolAccount = Get-SPManagedAccount -Identity $AppPoolAccount -ErrorAction SilentlyContinue
if($AppPoolAccount -eq $null)
{
Write-Host "Please Enter the password for the Service Account..."
$AppPoolCredentials = Get-Credential $AppPoolAccount
$AppPoolAccount = New-SPManagedAccount -Credential $AppPoolCredentials
}
#Check if the application pool exists already
Write-Host -ForegroundColor Yellow "Checking if the Application Pool already exists"
$AppPool = Get-SPServiceApplicationPool -Identity $AppPoolName -ErrorAction SilentlyContinue
if ($AppPool -eq $null)
{
Write-Host -ForegroundColor Green "Creating Application Pool..."
$AppPool = New-SPServiceApplicationPool -Name $AppPoolName -Account $AppPoolAccount
}
#Check if the Service application exists already
Write-Host -ForegroundColor Yellow "Checking if Managed Metadata Service Application exists already"
$ServiceApplication = Get-SPServiceApplication -Name $ServiceAppName -ErrorAction SilentlyContinue
if ($ServiceApplication -eq $null)
{
Write-Host -ForegroundColor Green "Creating Managed Metadata Service Application..."
$ServiceApplication = New-SPMetadataServiceApplication -Name $ServiceAppName -ApplicationPool $AppPoolName -DatabaseName $DatabaseName -DatabaseServer $DatabaseServer
}
#Check if the Service application Proxy exists already
$ServiceAppProxy = Get-SPServiceApplicationProxy | where { $_.Name -eq $ServiceAppProxyName}
if ($ServiceAppProxy -eq $null)
{
#Optional Parameters:
$ServiceApplicationProxy = New-SPMetadataServiceApplicationProxy -Name $ServiceAppProxyName -ServiceApplication $ServiceApplication -DefaultProxyGroup -ContentTypePushdownEnabled -DefaultKeywordTaxonomy -DefaultSiteCollectionTaxonomy -Uri $ContentTypeHub
}
#Start service instance
$ServiceInstance = Get-SPServiceInstance | Where-Object { $_.TypeName -eq "Managed Metadata Web Service" }
#Check the Service status
if ($ServiceInstance.Status -ne "Online")
{
Write-Host -ForegroundColor Yellow "Starting the Managed MetadataService Instance..."
Start-SPServiceInstance $ServiceInstance
}
Write-Host -ForegroundColor Green "Managed Metadata Service Application created successfully!"
}
catch {
Write-Host $_.Exception.Message -ForegroundColor Red
}
finally {
#Reset the Error Action to Default
$ErrorActionPreference = "Continue"
}
以下是上述 PowerShell 脚本创建托管元数据服务应用程序的结果:
您可以使用可选参数,例如服务应用程序将从中使用内容类型的内容类型中心的 URL。
