Home » Microsoft Technologies

How can I create a new Cache Cluster using powershell commands ?

I'm trying to put together an automated installation for AppFabric, doing lots of the configuration using a powershell script.

I can't find a command that I can use to create a new Cache Cluster; Beta 2 had commands that I can use, but the latest version has none.


Can anyone suggest an alternative way of creating a new Cache Cluster that can be fully automated ?





2 Answers Found


Answer 1

We have a Deployment and Management white paper that should help you with this:

Automated Installation and Configuration (Windows Server AppFabric Caching)


This link above walks through the PowerShell commands necessary to create the cache cluster, register cache hosts, etc. There is a sample AddCacheHost script here: http://msdn.microsoft.com/en-us/library/ff921024.aspx, and a sample RemoveCacheHost script here: http://msdn.microsoft.com/en-us/library/ff921034.aspx.

Let me know if you have any questions.


Jason Roth


Answer 2

Thanks for the assistance. I found those too and my solution is based on that exact "AddCacheHost" script, however, with the latest install of AppFabric (V6.1 I believe), some of the powershell commands are missing.


I started Powershell using the link created by the installer, as administrator, and tried to create a new cache cluster using the "New-CacheCluster" and this is what PS responds with:

PS C:\> New-CacheCluster
The term 'New-CacheCluster' is not recognized as the name of a cmdlet, function
, script file, or operable program. Check the spelling of the name, or if a pat
h was included, verify that the path is correct and try again.
At line:1 char:17
+ New-CacheCluster <<<<
    + CategoryInfo          : ObjectNotFound: (New-CacheCluster:String) [], Co
    + FullyQualifiedErrorId : CommandNotFoundException

PS C:\>


A list of all the cache related commands available in PS:

PS C:\> Get-Help *cache*

Name                              Category  Synopsis
----                              --------  --------
Clear-CacheLogging                Cmdlet    Disables all logging for the cur...
Export-CacheClusterConfig         Cmdlet    Export cache cluster configurati...
Get-Cache                         Cmdlet    Lists all caches and regions in ...
Get-CacheAllowedClientAccounts    Cmdlet    Get the list of Windows accounts...
Get-CacheClusterHealth            Cmdlet    Returns health statistics for al...
Get-CacheConfig                   Cmdlet    Returns the configuration detail...
Get-CacheHost                     Cmdlet    Lists all cache host services th...
Get-CacheHostConfig               Cmdlet    Returns the configuration detail...
Get-CacheRegion                   Cmdlet    Returns a list of all regions in...
Get-CacheStatistics               Cmdlet    Returns statistics for a Cache o...
Grant-CacheAllowedClientAccount   Cmdlet    Grants a Windows account permiss...
Import-CacheClusterConfig         Cmdlet    Import cache cluster configurati...
Invoke-CacheGC                    Cmdlet    Used to initiate .NET garbage co...
New-Cache                         Cmdlet    Creates a new named cache when t...
Remove-Cache                      Cmdlet    Removes the named cache specifie...
Restart-CacheCluster              Cmdlet    Restarts the Caching Service on ...
Restart-CacheHost                 Cmdlet    Restarts the Caching Service on ...
Revoke-CacheAllowedClientAccount  Cmdlet    Removes a Windows account from t...
Set-CacheClusterSecurity          Cmdlet    Sets the security settings used ...
Set-CacheConfig                   Cmdlet    Updates the configuration settin...
Set-CacheHostConfig               Cmdlet    Updates the configuration settin...
Set-CacheLogging                  Cmdlet    Updates the settings for adminis...
Start-CacheCluster                Cmdlet    Starts the Caching Service on al...
Start-CacheHost                   Cmdlet    Starts the Caching Service on th...
Stop-CacheCluster                 Cmdlet    Stops the Caching Services on al...
Stop-CacheHost                    Cmdlet    Stops the specified cache host s...
Test-CacheConfigAvailability      Cmdlet    Tests the connection with the ca...
Use-CacheCluster                  Cmdlet    Sets the context of your PowerSh...

PS C:\>


Any ideas ?


EDIT: The Powershell tool shortcut created by the installer didn't include the DistributedCacheConfiguration module, that's why I couldn't see/use the commands. I should get sorted from here onwards. Thanks for your time and assistance.


We are running Windows 2003 R2 SP2 x64 edition.  When using Velocity CTP3 using a shared UNC drive for configs (.sdf files), we are unable to create a new cache using the New-Cache command once the Velocity cluster has started.  The setting-up documentation for Velocity specifically says to start the cluster service before creating a new cache, but this information appears to be incorrect.  We have tried the manual's approach only to be lead to failure (see error below).

We are only able to create a new cache with the cache cluster stopped when using a shared drive on a UNC path.  If even one node in the cluster is running, no new caches can be created with New-Cache.  The error we receive is as follows:

PS C:\Program Files\Microsoft Distributed Cache\V1.0> New-Cache -CacheName test
New-Cache : ErrorCode<ERRTransport0002>:Unknown failure in transport layer.
At line:1 char:10
+ New-Cache <<<<  -CacheName test
    + CategoryInfo          : NotSpecified: (:) [New-Cache], DataCacheException
    + FullyQualifiedErrorId : ERRTransport0002,Microsoft.Data.Caching.Commands.NewCacheCommand

The problem is that it's not feasible to operate Velocity in this way as it's possible we will need to create new caches on the fly.  So, for the shared drive mode this is a show stopper for us.

We understand the workaround for this issue may be to use the MSSQL mode.  However, in order for us to use MSSQL, we will need to set up Windows clustering.  In order to cluster MSSQL under Windows clustering, MSDTC also needs to be clustered which requires a Physical Disk which further requires an iSCSI disk to be shared between multiple hosts in the cluster.  An iSCSI disk seems the only way to get Windows Clustering to recognize a physical disk for a quorum that can be used for the MSDTC->MSSQL dependencies.

It's not that we can't resolve all of these dependencies.  We can.  It just requires a lot more investment into getting this software working than we had first anticipated.  Considering that Velocity itself is supposed to have its own clustering mechanism, having to set up Windows clustering seems almost redundant strictly for this service, but I suppose that it is necessary for MSSQL to function when clustered.

The point here is that there's appears to be a bug in the shared drive version of Velocity that prevents new caches from being created when the cache cluster is active.

If there is a fix for this issue, please let me know.  Also, if this is not the correct forum for a bug report, please let me know this as well.




Trying to launch the "Caching Administration window PowerShell" to get access to the caching commands.  I am logged on as administrator.  I am getting this message when it launches a window,

Use-CacheCluster : ErrorCode<ERRCMS0001>:SubStatus<ES0001>:Error while trying to load configuration: An error occurred loading a configuration file: Logon failure: unknown user name or bad password.
At line:1 char:62
+ Import-Module DistributedCacheAministration;Use-CacheCluster <<<<
    + CategoryInfo          : NotSpecified: (:) [Use-CacheCluster], DataCacheException
    + FullyQualifiedErrorId : ERRCMS0001,Microsoft.ApplicationServer.Caching.Commands.UseCacheClusterCommand


What am i doing wrong here?

Trying to launch the "Caching Administration window PowerShell" to get access to the caching commands.  I am logged on as administrator.  I am getting this message when it launches the shell window,

Use-CacheCluster : ErrorCode<ERRCMS0001>:SubStatus<ES0001>:Error while trying to load configuration: An error occurred loading a configuration file: Logon failure: unknown user name or bad password.
At line:1 char:62
+ Import-Module DistributedCacheAministration;Use-CacheCluster <<<<
    + CategoryInfo          : NotSpecified: (:) [Use-CacheCluster], DataCacheException
    + FullyQualifiedErrorId : ERRCMS0001,Microsoft.ApplicationServer.Caching.Commands.UseCacheClusterCommand




I would like to use, cache service powershell commands from my C# code. which till now I have not been able to do .


I used code from this thread



but when i run this code, I am getting this error

The term 'Use-CacheCluster' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again.


I am using the code below



using (PowerShell ps = PowerShell.Create ())


ps.AddCommand (





"Name", "DistributedCacheAdministration");

ps.Invoke ();




ps.AddParameter (


"Provider", "xml");

ps.AddParameter (


"ConnectionString", @"\\nb-gjanjua.corp.geosign.com\localcache");



var results = ps.Invoke ();


Please note : I am using AppFabric 6.0

Thanks for the help


Hi all,

I'm currently trying to install a second, named instance (MSSQLSERVER already exists and is running) on an existing SQL 2008 R1 cluster (sitting on Windows 2008 R2).  I run the setup as normal and when I get to the Cluster Network Configuration screen, there is a blank screen underneath the headings for IPV4, DHCP, etc so I can't enter the IP address I have set aside for the cluster.

I've found 1 thread online that suggests this is due to the public network being down but this is not the case here as we are accessing the server via the public network.

I've tried re-starting the install process a number of times and re-booted the server as well but everytime I get to this screen I have the same issue.

Can anyone throw some light on this??






I wish to propose this question I've posted some time ago without having a raply.

I recently looked at the very interesting Technet article named "Deploy by using DBA-created databases (SharePoint 2010)"; I've noticed something strange in the following section:

To create and configure the portal site Web application

[DBA] Create the portal site Web application content database using the LATIN1_General_CI_AS_KS_WS collation sequence and set the database owner (dbo) to be the Setup user account.

[DBA] Using SQL ServerManagement Studio, add the service application service account to the Users group and then to the db_owner role for the portal site Web application content database.

[Setup] From the SharePoint 2010 Management Shell, use the New-SPWebApplication and Get-SPWebApplication cmdlets to configure the portal site Web application content database. Use the following example as a guide.

New-SPWebApplication -Name "Contoso Internet Site" -Port 80 -HostHeader "http://sharepoint.contoso.com" -URL "https://www.contoso.com" -ApplicationPool "ContosoAppPool" -ApplicationPoolAccount (Get-SPManagedAccount "DOMAIN\jdoe")
Get-SPWebApplication http://somesite | Set-SPWebApplication -Zone "Extranet" -HostHeader "http://www.contoso.com" - AllowAnonymousAccess
Well: if I create my database and apply the recommended collation and security, I would like to know how the New-SPWebApplication cmdlet and the Get-SPWebApplication cmdlet - in the way these  are written in the sample - are aknowledged about the existence of my database. My worry is that whern I execute the two cmdlets I'll find a new database named and dimensioned by default.


Hi All

I'm preparing myself for the 70-236 exam. After studying from CBT nugget videos I bought some test exams. Unsuprisingly there are alot of powershell commands, alot of setup /prepare domain (or similar) commands and possibly alot more else.

Apart from books does anyone have any good pages online i could use as a reference? I'm not sure watching the videos all over again and trying to note down whats there is the best idea. Plus I'm sure it only covers a fraction of it.

If not has anyone else got some other useful ideas? (again aside from buying a book or whatever)


Thanks in advance :)



I am using the powershell command New-SPSite to create a new instance of a custom site definition in SharePoint 2010.  Unfortunately it creates an empty site and none of the featues defined in the onet.xml of the custom site definition seem to get activated.  When I create this same site definition through the UI it works fine (features in the onet.xml do get activated).  Given below is the set of commands I use

$template = Get-SPWebTemplate "Custom#0"

New-SPSite -Url $SiteUrl –OwnerAlias domain\account –Template $template

Does anyone have any idea as to what is going wrong?



Is it possible to run powershell commands from VB.net and then grab the result.
Ex I need to query Exchange 2007/2010 information and present it in textboxes/listview/datagrid.

One exsample could be the below PS code.

#Mailbox Size Report
Get-Mailbox -ResultSize ‘Unlimited’| select @{Name=”User Name”;expression={$_.displayname}},
@{Name=”Department”;expression={(get-user $_.alias).department}},
@{Name=”Storage Group”;expression={$_.database}}, 
@{Name=”Total Size (MB)”;expression={(get-mailboxstatistics $_).totalitemsize.value.toMB()}}, 
@{Name=”ItemCount”;expression={(get-mailboxstatistics $_).itemcount}},
@{Name=”LastLogonTime”;expression={(get-mailboxstatistics $_).LastLogonTime}} | Sort-Object -property  ‘Total Size (MB)’ -descending




I am following a tutorial for manually installing and configuring AppFabric Caching at the following link:


It seems that I am missing even the "New-CacheCluster" command.

I am running the Powershell module as administrator, and I installed the Cache Services and Cache Administrator features.

My workstation is Windows 7 (32-bit)

Were these commands only used in an earlier beta or something?


Can you please show me how to move all the LDF files in my SQL Server instance to a different disk ?


I have added a new disk to my server and want to dedicate it to ldf files. I want to write a powershell script to move all the ldfs to this disk.


I am able to add a new file using Powershell.... but how to remove the previous one..


$databases = dir
foreach($database in $databases)
  $fileGroups = $database.FileGroups
  foreach($fileGroup in $fileGroups) 
    $newLogFile = New-Object ('Microsoft.SqlServer.Managerment.Smo.DataFile')($fileGroup, ("E:\" + $database.Name + "_Log.ldf"))


I need to get list of all SharePoint 2010 sites with following details:-

- Content database

- Site owner

- Size, etc.

I used enumsites in MOSS 2007. How can we get it in SharePoint 2010?



I'm new to bringing C# and Powershell together, but am hoping to create a web page that leverages Powershell in the back end.  I realize that what I am doing can be done solely with C#, but would like to figure this out for other applications.  

Essentially, I am taking the name of a new web application from a web form and getting the authenticated user's username for physical path mapping. 

My Powershell code works correctly (even when copying it directly from Pipeline.Commands[0] directly), but it does not appear to do anything when I run it.  I get parameter errors if I force one (ex: make -physicalpath a non-existent path), but with all parameters correct, the variable result only contains one blank item.  

Does this sound like a C# or IIS Powershell module issue?  Any ideas how I get more information returned from my command?  

protectedvoid Button1_Click(object sender, System.EventArgs e)
      String username = getUser();
      String physicalPath = "S:\\WebSites\\" + username + "\\public_html\\" + TextBox1.Text; 
      // Create Powershell Runspace
      Runspace runspace = RunspaceFactory.CreateRunspace();


      // Create pipeline and add commands
      Pipeline pipeline = runspace.CreatePipeline();
        "Import-Module WebAdministration; set-psdebug -trace 1; " +

        "New-WebApplication -Site MySite" +
        " -Name " + TextBox1.Text +
        " -PhysicalPath " + physicalPath +
        " -ApplicationPool WebSites -Verbose -force");


      // Execute Script
      Collection<PSObject> results = new Collection<PSObject>();
        results = pipeline.Invoke();
      catch (Exception ex)
        results.Add(new PSObject((object)ex.Message));

      // Close runspace

      //Script results to string
      StringBuilder stringBuilder = new StringBuilder();
      foreach (PSObject obj in results)




I wan to create an application to install my solution (with other things such as wcf...) automatically to sharepoint 2010. To do so I'm running a pwoershell script from the application using the following code:

using (PowerShell ps = PowerShell.Create())
    ps.Commands.AddScript(psScript).AddParameter("webApp", "http://{webapp}").AddParameter("$currDir", scriptPath);

    Collection<PSObject> returnObjects = ps.Invoke();


The scriptPath parameter directs the powershell script to a folder where all my solutions are. the webApp parameter is self explanatory :).


the powershell script is:

Add-SPSolution -LiteralPath $SolutionPath
Install-SPSolution –identity $solutionName -GACDeployment -WebApplication $webApp

where $SolutionPath shows the wsp file location and $solutionName is the solution name.

I can run the script with no problem using the powershell commandline but when I try to runit with C# I get the following error:

"A positional parameter cannot be found that accepts argument '{Solution name}'."

I did some investigation and came up with this - the Install-SPSolution thinks for some reason that the solutionName paramter is a positional one but I can't find why it "thinks so"




Just installed two new servers today (2008 R2) and for the first time installed Appfabric RTM (previously did AppFabric beta2 refresh and Upgraded to RTM and
before that Velocity CTP3)

The following unexpected behaviour occurs when I set the service to automatic startup:

Only the cluster seems to start since only port 22234 is listening in "netstat -an ".

I previously used to call a powershell on startup with the following in it

"powershell -command Import-Module DistributedCacheAdministration, DistributedCacheConfiguration; Use-CacheCluster ;Start-CacheCluster ;"

This now fails to startup the hosts (it says the cluster and hosts are up in fact) and still only port 22234 is listening.

If i revert to how i used AppFabric pre-RTM then all i do keep the service as manual startup and call this powershell.

Then everything works fine and the cluster (22234) and cache (22233) et al are listening and the the cache is usable.

Seems like using auto startup buggers things up and the cache cant be started?

Summary - use autostartup - and the cache wont start (must stop service and start using powershell)

or dont use autostartup and use powershell which is not ideal...

Further info:

Running in a work group - created a user called AppFabric, set the logon as service and generate security audits.

Using XML config:

            <host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
                hostId="2070834366" size="3067" leadHost="true" account="ANTLAP\AppFabric"
                cacheHostName="AppFabricCachingService" name="ANTLAP" cachePort="22233" />




Hi All,

I have a simple question since I am new in AppFabric. I have set up a cluster with 3 machines. One as a Lead Host with SQL Server and two as a cache host. I think the lead host is just as an adminstarator in the cluster and do not perform any caching action. So, when i use Get-Cache command, I just can see only those two cache host have caches. My question is, when I'm writing an ASP.NET apps, which host should I add in the web.config? Or simply add those three in? Thanks.


Hi all,

Quick question:  I have read that in order for AppFabric cache clustering to work, you actually have to install the services on Windows 2008 Enterprise Servers (why?!?).

My question is this:  If I want to have a distributed cache that is more simply partitioned (i.e. 2 cache servers working together as a single cluster, and having applications read/write objects to them by not using any Regions), does that require Enterprise Server as well?  I don't care about failover and backup of my session objects, but I do have a large number of objects that I wish to partition across multiple servers.  I certainly do not want to pay upwards of $10k to upgrade my Windows servers boxes just to have a segmented/partitioned caching system.

We would really like to start using AppFabric cache, but if MS is going to force us into Enterprise server for a basic partitioned and distributed caching service, we will probably end up having to go with memcached.



I was told by the windows admin that you cannot disable write caching in windows server 2008 when the drives are clustered. Can someone please tell me how to turn it off. I find it very hard to believe you cannot turn it off. i know on a normal server how to do it, by right clicking the drive, properties, hardware, click on the drive, click properties, uncheck write caching...However, this is disabled on my cluster. 

Q: how velocity work with concurrency on different cluster nodes?

ex : If i've installed 2 cache cluster nodes and one cache client (CLT1)  is changing  cacheitem[KEY1] from 2 to 1 and in the same time another cache client (CLT2)  is reading from another nodes the cacheitem[KEY1] what is the result sent to CLT2 ? 1 or 2 ?




Dear Microsoft and Microsoft Product Enthusiasts,

A while ago, a server of mine left our cluster and turned itself off, and I am having trouble finding it (physically).  How can I remove this host from the cluster using the Powershell based configuration utility from my cache administration throne?  SQL server isn't the quorum host and I can't open the database manually 'cause it's locked.


<< Previous      Next >>

Microsoft   |   Windows   |   Visual Studio   |   Sharepoint   |   Azure