Hi,
in this blog post of my “SharePoint 2010: exploring the managed metadata service application” post series we are going to see how a new managed metadata service application is created manually and programmatically with PowerShell.
Overview
A SharePoint farm that has managed metadata available can organize the managed metadata in several managed metadata service applications. Each managed metadata service application can serve with a proxy connection none or multiple web applications. This gives you the possibility to manage your metadata in a flexible way.
Each managed metadata service application has an service application pool assigned to it and usually also a managed account as application pool identity (check this blog post if you don’t know what managed accounts are). Last but not least, the “Managed Metadata Web Service” must run on at least one front-end to ensure that the managed metadata service is working properly.
In this post we are going to see how to create such a managed metadata service application. The content is organized as follows:
- Part 1: Creating a managed metadata service application with the central admin
- Part 2: Creating a managed metadata service application with PowerShell
Part 1: Creating a managed metadata service application with the central admin
Creating a managed metadata service application with the central admin is simple. Before starting we have to ensure that we have a managed account registered that we will use as a service application pool identity for our managed metadata service application (check this blog post if you don’t know what managed accounts are). In addition, we have to start the “Managed Metadata Web Service” service on at least one front-end server of our farm. You can do this by following these steps:
-
open the central admin
-
go to “Application Management” –> “Manage services on server”
-
start the “Managed Metadata Web Service” on any front-end server of your farm
Now, that all requirements are met, we can start creating our managed metadata service application. Follow these steps:
-
open the central admin
-
go to “Application Management” –> “Manage Service Applications”
-
press the “New” button on the ribbon and choose “Managed Metadata Service”
- a new window will popup configure it to your needs (see next pictures) and then press “OK”:
- Name: define the name for your managed metadata. This name will be shown on the “Manage Service Applications” overview page
- Database Server: specify the database server to store your managed metadata service database
- Application Pool: define a new application pool that will be used as service application pool identity for your managed metadata service application. Also define the managed account that you will use as application pool identity for this application pool
- Content Type hub: you can specify here the URL of the content type hub of your managed metadata service application. We will see this functionality later on in our post series. Just leave it empty for now.
- you should see something like in the next picture in the “Manage Service Applications” overview
With these small steps you created a managed metadata service application and the proxy. If you click on the name of the newly created service application, you are automatically redirected to the term store tool needed to manage your metadata in this store.
Please note that you are able to create multiple managed metadata service applications like that. On most cases these steps are enough to create a new managed metadata service application. However, we will see in the next part how to create the same stuff in a more automated way. Let us jump directly into the PowerShell script.
Part 2: Creating a managed metadata service application with PowerShell
The creation of the managed metadata service application with PowerShell is pretty straightforward. Now, we should know the different prerequisites needed to create the new service application. Because of that, it should not be difficult to understand the steps that are scripted in the PowerShell script that I prepared for you. Before we are going to see the whole script, I would like to summarize the steps that are execute in it:
- check if there is an service application pool with a specified name. If not, then create a new service application pool and assign the required managed account to it
- check if there is a managed metadata service application with a specified name. If not, then create it and assign it to the previously selected service application pool.
- check if there is a managed metadata service application proxy with a specified name. if not, then create it and assign it to the previously selected managed metadata service application.
You can execute this script more than once without breaking the previously created entities. The script always looks before if the item that we are going to create was already created. It uses the object if it finds something already defined. The complete script is shown in the next code snippet. The paragraphs after explain the different parts more in detail.
# start script configuration section
# service application and service application proxy names $metadataServiceApplicationName = "Demo Managed Metadata" $metadataServiceApplicationNameProxy = "Demo Managed Metadata Proxy" # service application pool identity for the service application $serviceApplicationPoolManagedAccountName = "LAMBERspman_app" # service application pool name $metadataApplicationPoolName = "managed_demo_appl" # end script configuration section $snapinName = "Microsoft.SharePoint.PowerShell" if ((Get-PSSnapin | Where-Object {$_.Name -eq $snapinName }) -eq $NULL) { write-host "SharePoint SnapIn not loaded. Loading..." Add-PSSnapin $snapinName } write-host "Starting managed application creation..." write-host write-host "Verifying running instances..." $metadataServiceInstanceName = "Managed Metadata Web Service" $onlineServiceInstances = Get-SPServiceInstance | where {$_.TypeName -eq $metadataServiceInstanceName -and $_.Status -eq "Online"} if ($onlineServiceInstances -eq $NULL) { write-host "No running instances found. Starting all service instances now..." $disabledServiceInstances = Get-SPServiceInstance | where {$_.TypeName -eq $metadataServiceInstanceName -and $_.Status -eq "Disabled" } $disabledServiceInstances | Start-SPServiceInstance while (-not ($disabledServiceInstances -eq $NULL)) { write-host "Waiting that all service instances are provisioned. Going to sleep for 10 seconds..." sleep 10; $disabledServiceInstances = Get-SPServiceInstance | where {$_.TypeName -eq $metadataServiceInstanceName -and $_.Status -eq "Disabled" } } write-host "All service instances provisioned successfully." } else { write-host "At least one instance is running in the farm." } write-host write-host "Verifying if '$metadataApplicationPoolName' service application pool exists..." $serviceApplicationPool = Get-SPServiceApplicationPool $metadataApplicationPoolName -ea SilentlyContinue if ($serviceApplicationPool -eq $NULL) { write-host "No service application pool found. Starting the creation process..." write-host "Verifying if '$serviceApplicationPoolManagedAccountName' is registered as managed account..." $managedAccountEntry = Get-SPManagedAccount $serviceApplicationPoolManagedAccountName -ea SilentlyContinue if ($managedAccountEntry -eq $NULL) { write-host "No managed account found. Starting the registering process..." $manCredentials = Get-Credential $serviceApplicationPoolManagedAccountName $managedAccountEntry = New-SPManagedAccount $manCredentials } else { write-host "Account already registered." } $serviceApplicationPool = New-SPServiceApplicationPool $metadataApplicationPoolName -Account $managedAccountEntry } else { write-host "Service application pool already exists." } write-host $ServiceApplication = Get-SPMetadataServiceApplication $metadataServiceApplicationName write-host "Verifying if '$metadataServiceApplicationName' already exists..." if ($ServiceApplication -eq $NULL) { write-host "No service application found. Starting the creation process..." $ServiceApplication = New-SPMetadataServiceApplication -Name $metadataServiceApplicationName -ApplicationPool $serviceApplicationPool write-host "Service application created successfully." } else { write-host "Service application already exists." } write-host $ServiceApplicationProxy = Get-SPMetadataServiceApplicationProxy $metadataServiceApplicationNameProxy write-host "Verifying if '$metadataServiceApplicationNameProxy' service application proxy already exists..." if ($ServiceApplicationProxy -eq $NULL) { write-host "No service application proxy found. Starting the creation process..." $ServiceApplicationProxy = New-SPMetadataServiceApplicationProxy -Name $metadataServiceApplicationNameProxy -ServiceApplication $ServiceApplication write-host "Service application proxy created successfully." } else { write-host "Service application proxy already exists" } write-host write-host "Managed application creation finished."
Now, let us analyze the different parts of this script and explain those better. The next code snippet shows the first part of the script. This part is self-explanatory and is used to configure the creation of the managed metadata service application. Change these values to your needs before starting the script.
# start script configuration section # service application and service application proxy names $metadataServiceApplicationName = "Demo Managed Metadata" $metadataServiceApplicationNameProxy = "Demo Managed Metadata Proxy" # service application pool identity for the service application $serviceApplicationPoolManagedAccountName = "LAMBERspman_app" # service application pool name $metadataApplicationPoolName = "managed_demo_appl" # end script configuration section
The next code snippet checks if the “Managed Metadata Web Service” runs on at least one front-end server. If this is not the case, all “Managed Metadata Web Service” instances are taken and started on all servers. The while loop checks every 10 seconds if all services already run. If not, it waits for other 10 seconds.
write-host "Verifying running instances..."
$metadataServiceInstanceName = "Managed Metadata Web Service"
$onlineServiceInstances = Get-SPServiceInstance | where {$_.TypeName -eq $metadataServiceInstanceName -and $_.Status -eq "Online"}
if ($onlineServiceInstances -eq $NULL) {
write-host "No running instances found. Starting all service instances now..."
$disabledServiceInstances = Get-SPServiceInstance | where {$_.TypeName -eq $metadataServiceInstanceName -and $_.Status -eq "Disabled" }
$disabledServiceInstances | Start-SPServiceInstance
while (-not ($disabledServiceInstances -eq $NULL)) {
write-host "Waiting that all service instances are provisioned. Going to sleep for 10 seconds..."
sleep 10;
$disabledServiceInstances = Get-SPServiceInstance | where {$_.TypeName -eq $metadataServiceInstanceName -and $_.Status -eq "Disabled" }
}
write-host "All service instances provisioned successfully."
}
else {
write-host "At least one instance is running in the farm."
}
write-host
The next code snippet shows that the script continues by verifying if there is already a service application pool with the name specified in the configuration section of the script. If this is the case, the service application pool is used for the next steps. Otherwise, a new service application pool is created.
The creation of the service application pool first verifies if a managed account with the name specified in the configuration section already exists. If this is not the case, the managed account is registered. Please note that you will be prompted for credentials if a new managed account is going to be registered. After this step, the managed account is assigned as application pool identity for the newly created service application pool.
write-host "Verifying if '$metadataApplicationPoolName' service application pool exists..."
$serviceApplicationPool = Get-SPServiceApplicationPool $metadataApplicationPoolName -ea SilentlyContinue
if ($serviceApplicationPool -eq $NULL) {
write-host "No service application pool found. Starting the creation process..."
write-host "Verifying if '$serviceApplicationPoolManagedAccountName' is registered as managed account..."
$managedAccountEntry = Get-SPManagedAccount $serviceApplicationPoolManagedAccountName -ea SilentlyContinue
if ($managedAccountEntry -eq $NULL) {
write-host "No managed account found. Starting the registering process..."
$manCredentials = Get-Credential $serviceApplicationPoolManagedAccountName
$managedAccountEntry = New-SPManagedAccount $manCredentials
}
else {
write-host "Account already registered."
}
$serviceApplicationPool = New-SPServiceApplicationPool $metadataApplicationPoolName -Account $managedAccountEntry
}
else {
write-host "Service application pool already exists."
}
write-host
In the next code snippet the script is going to create the managed metadata service application (if it does not already exist) and assigns the service application pool that was defined before.
$ServiceApplication = Get-SPMetadataServiceApplication $metadataServiceApplicationName
write-host "Verifying if '$metadataServiceApplicationName' already exists..."
if ($ServiceApplication -eq $NULL) {
write-host "No service application found. Starting the creation process..."
$ServiceApplication = New-SPMetadataServiceApplication -Name $metadataServiceApplicationName -ApplicationPool $serviceApplicationPool
write-host "Service application created successfully."
}
else {
write-host "Service application already exists."
}
write-host
In the last code snippet the script creates the managed metadata service application proxy (if it does not already exist) and assigns it to the managed metadata service application that we created before.
$ServiceApplicationProxy = Get-SPMetadataServiceApplicationProxy $metadataServiceApplicationNameProxy
write-host "Verifying if '$metadataServiceApplicationNameProxy' service application proxy already exists..."
if ($ServiceApplicationProxy -eq $NULL) {
write-host "No service application proxy found. Starting the creation process..."
$ServiceApplicationProxy = New-SPMetadataServiceApplicationProxy -Name $metadataServiceApplicationNameProxy -ServiceApplication $ServiceApplication
write-host "Service application proxy created successfully."
}
else {
write-host "Service application proxy already exists"
}
write-host
Summary
Creating a new managed metadata service application for a SharePoint farm is an easy task manually and programmatically. In this blog post we saw how it is done in both ways and what are the requirements needed before executing these steps. In the next blog posts of this post series we are going to see better how to use the managed metadata service application.
Hope this helps,
Patrick


Hi
I have created the service application using your script, but i am unable to see in the drop down of all available service applications in Term Store Management Tool. It should be there.
just a quick question/comment. your powershell script doesnt seem to make reference to a database server or a database name… why is that ?
Thanks Patrick, specially for the PowerShell script. Keep on the good work!