Monthly Archives: August 2016

New-SPMetadataServiceApplication hangs

This SharePoint Powershell command stalls: “New-SPMetadataServiceApplication”

Using the AutoSPInstaller script, the deployment hangs.
The script finally stalls with the following:

Provisioning Managed Metadata Service Application
Creating SharePoint Hosted Services Application Pool…
Starting Managed Metadata Service:
Starting Metadata Service Instance…
Waiting for Metadata service…Online
Creating Metadata Service Application…

 

ULS Log:

Blocking until timer job ‘—GUID—‘ has completed.

 

Get-SPTimerJob doesn’t give any result when referencing the mentioned GUID.

After an undetermined period of time, it finally errored out with:

 

Solution

Solved by a re-run after deleting the “half” created service application and adding/activating the Registry/Policy item DisableForceUnload.

Registry entry:

 

Powershell:

 

Manual GUI setting:
Local Group Policy Editor > Local Computer Policy > Computer Configuration > Administrative Templates > System > User Profiles > “Do Not Forcefully Unload The Users Registry At User Logoff” > Enabled

 

Group Policy Filename:
UserProfiles.admx > “Do not forcefully unload the users registry at user logoff”

 

Other people with the same problem: autospinstaller.codeplex.com/workitem/19457

Getting Use-CacheCluster to work on a SharePoint server without the AppFabric Distributed Cache Role/Component

You probably have encountered it already some time ago. You want to check the status of your Distributed Cache Cluster and you login to a back-end server where there is no Distributed Cache component.
You open up Powershell and start with Use-CacheCluster. It fails. You failed. You need to login to a server which is an active member of the Distributed Cache Cluster to get the status, configuration, etc.

Now there is a simple solution which does not effect your application.

 

Some examples you might get when trying to connect to the AppFabric Distributed Cache cluster from a SharePoint server:

 

I have been on a gooze chase for a while because of articles like this:


 

use-cachecluster
use-cachecluster -Provider “System.Data.SqlClient” -ConnectionString “Data Source=dbmachine\instance;Initial Catalog=DatabaseName;Integrated Security=true”

http://blog.milrr.com/2012/05/code-appfabric-diagnostic-powershell.html


 

Use-CacheCluster
Sets the context of your Windows PowerShell session to the desired cache cluster.

When you start a Windows PowerShell session, you must first run this command. If it is on a cache host, you run the command with no parameters, because the parameters are taken from the cache configuration on the computer. If you are running it from a non-host computer, you can use the parameters below to specify the desired cache cluster.

Parameter (alias) descriptions are as follows:

Provider (P): The provider that is used to store the cluster configuration settings. This can be eitherSystem.Data.SqlClient or XML depending on how the configuration information is stored.
ConnectionString (C): The connection string to the database or location of the XML configuration file.

https://msdn.microsoft.com/en-us/library/ff718177(v=azure.10).aspx


 

 

How to do it

Thankfully, there is a solution:
The Use-CacheCluster can be helped with the directions where to find the cluster configuration. All it needs is some registry entries.
No problems or errors will occur, you are not activating services or changing the config within SharePoint. Just the registry on the server(s) where you want to be able to look at the Cache Cluster.
This is, because every SharePoint 2013 server gets the same AppFabric installation, because its a prerequisite component.
That means the Powershell modules, DLL files and basic registry entries are already in place.

We only need to add a few properties.

 

We can create these very easy:

 

Now, when we use Use-CacheCluster on a SharePoint 2013 server where Distributed Cache is not configured, it works!

 

Working with Get-CacheClusterHealth and judge the results in scripts/checks

The AppFabric Distributed Cache Service is an important yet fragile part of SharePoint 2013. To get the last status and for example use it in your monitoring might be a wanted solution to get a trigger when something is wrong with it.
The command “Get-CacheClusterHealth” gives a lot of textual results about the current state of all caches and cachehosts, which can be good, but is difficult to use and to interpret. The result is of type “Microsoft.ApplicationServer.Caching.Commands.ClusterHealth”.
The formatting is text, not objects as we are used to in Powershell. Furthermore, the structure is not consistent as such to easily convert to objects, the hostname is mentioned once and then all NamedCaches are listed without referencing the hostname again.

The output is explained in this Microsoft article: technet.microsoft.com/en-us/library/ff921010.aspx

The result is nicely described in this table on referenced TechNet article:

Health Category Description
Healthy The cache is operating normally. This is the target state for all caches.
UnderReconfiguration The cache is under reconfiguration. This is an internal state that may have several causes, but it should be temporary and resolve to healthy.
NotPrimary The cache is not currently available. This can happen when secondary copies are promoted to primary. During this transition, the cache may temporarily have a state of NotPrimary. This state should typically resolve to healthy.
NoWriteQuorum The cache is read-only, because the cache is unable to create the required number of replicas on secondary cache hosts. This occurs when the cache has the high availability option enabled (Secondaries = 1). In this scenario, there must be at least two running cache hosts in the cluster, one for the primary copy of the cached item and another for the secondary copy.
Throttled The cache is read-only, because the cache host is in a throttled memory state. This is a low-memory condition.

 

The actual output looks like this (fragment):

 

Writing code to convert the result

I couldn’t find a working solution to handle the data, so I wanted to create my own. Its based on regular expressions. My inspiration comes from this example: msgoodies.blogspot.nl/2008/12/matching-multi-line-text-and-converting.
It took me some time to get the regex working, but I finally found a way in which the CacheClusterHealth can be used in an automated script that can regularly check the Health and trigger an alert if anything is wrong.

In each line of output, the “property name” is stated before the value, like “HostName = SP2013FE2.local.nl” and “Healthy = 5,00”, in the end result we want to have each property associated to each NamedCache per Host. That last part needed some more fine-tuning.

HostName NamedCache Healthy UnderReconfiguration NotPrimary InadequateSecondaries Throttled
 SP2013Fe  DistributedSecurityTrimmingCache_<<GUID>>  5  0  0  0  0
 SP2013FE  DistributedSearchCache_<<GUID>>  5  0  0  0  0
 SP2013FE  DistributedViewStateCache_<<GUID>>  5  0  0  0  0
 …  …
 SP2013FE2  DistributedSecurityTrimmingCache_<<GUID>>  5  0  0  0  0

The script: regex

The first part consists of the regex, it has 2 blocks surrounded by round brackets, the difference between the 2 is that the first one is with hostname and the second without. That’s because we first encounter a namedcache that is preceded by the hostname, and after that the other namedcaches are listed for that same hostname without referencing the hostname again.

In this regex we lookup each property by it’s name and the equal sign, the \s+ is used as “one or more whitespace characters”. The actual value is extracted using /S+ which means “one or more characters of anything but whitespace type”. We make sure that the result includes each property name enclosed in the lesser-than and greater-than signs, which will be used in the Powershell Object creation.

 

 

The script: matches to objects

The next part handles the results of the regex matches, important is we group by hostname because we only get the hostname once for all caches that are related to that hostname, so we safe it in the $hostname variable.

 

Examples to determine the health based on the script

Update: CAUTION: This next part is fundamentally wrong!

 

The last part consists of some examples to use the data:

 

The end result might look like: