Tuesday, July 21, 2015

All Webs and Site Templates in use within a Site Collection PowerShell Script

$site = Get-SPSite "http://yoursite"

foreach ($web in $site.AllWebs) {

$web | Select-Object -Property Title,Url,WebTemplate

}

$site.Dispose()

Monday, July 20, 2015

Get list of all users present in a site under different SharePoint Groups

Background:

I wanted to see all users who have access to the SharePoint site and belongs to which SharePoint group.

Solution:

Below SharePoint powershell script helps me to get list of users group wise-


$site = Get-SPSite <Provide Site Collection URL here>
$web = $site.OpenWeb()
$groups = $web.sitegroups
 
foreach ($grp in $groups) {
    "Group: " + $grp.name;
    $groupName = $grp.name
    write-host "Group: " $groupName   -foregroundcolor green
    foreach ($user in $grp.users) {
            "User: " + $user.name
            write-host "User " $user.UserLogin   -foregroundcolor red
    }
}

Usage:

  • Navigate to Script location and type below command-

GetUsers.ps1

This will show output on screen.
  • Navigate to Script location and type below command-

GetUsers.ps1 | Out-File C:\Output.csv

This will generate output as csv file. "C:\Output.csv" is the file name and location where generated csv file is saved. Please change as per your requirement.

Tuesday, May 5, 2015

Configuring SQL Server 2014 AlwaysOn Availability Group using PowerShell

Introduction
Earlier on I was trying to search for some scenarios to implement AlwaysOn Availability Groups using PowerShell, although I was able to find some interesting post however non of them represented a complete scenario starting from a fresh windows server installation (using PowerShell), so I decided to write this blog as quick walkthrough thePowerShell scripts needed.
Sample Scenario
In this scenario I will be using a 2 Nodes setup with the following software already installed:
  • Windows Server 2012 R2
  • Both Servers are joined to the domain
Configuration Steps:
To make the scenario simple I be using a Domain Account that has a Local Administrator Permission on both nodes. In addition, all scripts below will be running using PowerShell (Run as Admin) so Lets get started:
1- Install SQL Server
We need to install a standalone setup on each node. I will do that using the below sample unattended SQL Setup Script:
Setup.exe /q /ACTION=Install /FEATURES=SQL /INSTANCENAME=MSSQLSERVER /SQLSVCACCOUNT="<DomainName\UserName>" /SQLSVCPASSWORD="<StrongPassword>" /SQLSYSADMINACCOUNTS="<DomainName\UserName>" /AGTSVCACCOUNT="<DomainName\UserName>" /AGTSVCPASSWORD="<StrongPassword>"   /IACCEPTSQLSERVERLICENSETERMS
2- Add Windows Failover Cluster
We need to install it on each node. I will do that using the below script:
Import-Module ServerManager
Add-WindowsFeature Failover-Clustering –IncludeAllSubFeature
Install-WindowsFeature -Name Failover-Clustering –IncludeManagementTools
3- Configure Windows Failover Cluster
Run the below script on the 1st Node and make sure to update the configuration parameters with your values:
#----------------------------------------------------
# Configuration Parameters
#----------------------------------------------------
$Server1 = "Server1"
$Server2 = "Server2"
$IPAddress = "X.X.X.X"
$AlwaysOnClusterName = "ClusetrName"
$QuorumFileSharePath = "\\FileSharePath\"
#----------------------------------------------------
# Create Cluster Service
# Create a new cluster ‘AlwaysOnCluster’ with nodes.
#----------------------------------------------------
Import-Module FailoverClusters
New-Cluster –Name $AlwaysOnClusterName –Node $Server1,$Server2 -StaticAddress $IPAddress -NoStorage
# Add Quorum
Set-ClusterQuorum -NodeAndFileShareMajority $QuorumFileSharePath
4- Configure AlwaysOn Failover Cluster
Now for the fun part, I have configured the whole AlwaysOn Configuration in one script that needed to be ran on the 1st Node. In addition, I have added the proper comments so take your time to review it  and make sure to update the configuration parameters with your values:
#Set execution policy
Set-ExecutionPolicy unrestricted
# Import SQLPS Module
Import-Module “sqlps” -DisableNameChecking
#----------------------------------------------------
# Configuration Parameters
#----------------------------------------------------
#Server Names
$Server1 = "Server1"
$Server2 = "Server2"
$ServerInstance1 = '$Server1\Instance'
$ServerInstance2 = '$Server2\Instance'
#AlwaysOn TempDB Names
$tmpDB1 = "AG1-TempDB"
#Availability Group Names
$AG1Name="AG-1"
#Availability Group Listener
$AGListner1Name = "Listener1"
$Listner1IP_Mask = "X.X.X.X/X.X.X.X"
$ListnerPort= "1433"
$FileSharePath = "\\FileSharePath\"
#Service Accounts
$SQLSVCAccount = "Domain\SVCAccount"
$AGDomain = ".contoso.com" #Keep the '.' before domain name
#AlwaysOn EndPoints
$AOEndpointName = "AlwaysOnEndpoint"
$AOPort = "5022"
$AOEncryptionAlgorithm = "AES"
#----------------------------------------------------
# Enable AlwaysOn on Servers
#----------------------------------------------------
Enable-SqlAlwaysOn –ServerInstance $Server1
Enable-SqlAlwaysOn –ServerInstance $Server2
#----------------------------------------------------
# Create Endpoints
#----------------------------------------------------
#####1st Server
$AOtmpPath = "SQLSERVER:\SQL\$Server1\default"
New-SqlHadrEndpoint -Path $AOtmpPath -Name $AOEndpointName -Port $AOPort -EncryptionAlgorithm $AOEncryptionAlgorithm
# start the endpoint
$AOtmpPath = "SQLSERVER:\SQL\$Server1\default\endpoints\AlwaysOnEndpoint"
Set-SqlHadrEndpoint –Path $AOtmpPath –State "Started";
####2nd Server
$AOtmpPath = "SQLSERVER:\SQL\$Server2\default"
New-SqlHadrEndpoint -Path $AOtmpPath -Name $AOEndpointName -Port $AOPort -EncryptionAlgorithm $AOEncryptionAlgorithm
# start the endpoint
$AOtmpPath = "SQLSERVER:\SQL\$Server2\default\endpoints\AlwaysOnEndpoint"
Set-SqlHadrEndpoint –Path $AOtmpPath –State "Started";
#----------------------------------------------------
# Grant Permissions for EndPoints
#----------------------------------------------------
$SQLPermissionQry = "
USE [master]
GO
CREATE LOGIN $SQLSVCAccount FROM WINDOWS WITH DEFAULT_DATABASE=[master]
GO
GRANT ALTER ANY AVAILABILITY GROUP TO $SQLSVCAccount
GO
GRANT CONNECT SQL TO $SQLSVCAccount
GO
GRANT VIEW SERVER STATE TO $SQLSVCAccount
GO
"
Invoke-Sqlcmd -Query $SQLPermissionQry -ServerInstance $ServerInstance1
Invoke-Sqlcmd -Query $SQLPermissionQry -ServerInstance $ServerInstance2
#----------------------------------------------------
#Create Temp DB for AG
#----------------------------------------------------
$AOtmpPath = "SQLSERVER:\SQL\$Server1\default"
$svr = Get-Item $AOtmpPath
$db1 = New-Object Microsoft.SqlServer.Management.Smo.Database($svr, $tmpDB1);
$db1.Create();
#----------------------------------------------------
#Initial Backup for the DB
#----------------------------------------------------
cd "SQLSERVER:\SQL\$Server1\default\databases"
Backup-SqlDatabase –ServerInstance $Server1 –Database $tmpDB1;
#------------------------------------------------
# Backup & Restore TempDBs to prepare for AlwaysOn
#------------------------------------------------
#Backup
Backup-SqlDatabase –ServerInstance $Server1 –Database $tmpDB1 –BackupFile "$FileSharePath$tmpDB1.bak";
Backup-SqlDatabase –ServerInstance $Server1 –Database $tmpDB1 –BackupAction Log –BackupFile "$FileSharePath$tmpDB1.trn";
# Restore
cd "SQLSERVER:\SQL\$Server1\default"
Restore-SqlDatabase –ServerInstance $Server2 –Database $tmpDB1 –BackupFile "$FileSharePath$tmpDB1.bak" –NoRecovery;
Restore-SqlDatabase –ServerInstance $Server2 –Database $tmpDB1 –RestoreAction Log –BackupFile "$FileSharePath$tmpDB1.trn" –NoRecovery;
#---------------------------------------------
#Create AG Replica
#It assumes SynchronousCommit + Automatic Failover
#---------------------------------------------
$PrimaryRepTCP = "TCP://$Server1$AGDomain" + ':' + "$AOPort"
$SecondaryRepTCP = "TCP://$Server2$AGDomain" + ':' + "$AOPort"
$Primary = new-sqlavailabilityreplica -Name $Server1 -EndpointUrl $PrimaryRepTCP -ConnectionModeInPrimaryRole "AllowAllConnections" -ConnectionModeInSecondaryRole "AllowAllConnections" –AvailabilityMode "SynchronousCommit" –FailoverMode "Automatic" -AsTemplate -Version 11;
$Secondary = new-sqlavailabilityreplica -Name $Server2 -EndpointUrl $SecondaryRepTCP -ConnectionModeInSecondaryRole "AllowAllConnections" –AvailabilityMode "SynchronousCommit" –FailoverMode "Automatic" -AsTemplate -Version 11;
#---------------------------------------------
#Create a new AG
#---------------------------------------------
$ag = New-SqlAvailabilityGroup -Name $AG1Name -AvailabilityReplica ($Primary, $Secondary) -Database $tmpDB1
#---------------------------------------------
#Join Availability Replica
#---------------------------------------------
$AOtmpPath = "SQLSERVER:\SQL\$Server2\default"
Join-SqlAvailabilityGroup –Path $AOtmpPath –Name $AG1Name;
#---------------------------------------------
#Join Replica Database on a Secondary replica
#---------------------------------------------
$agpath1 = "SQLSERVER:\SQL\$Server2\default\AvailabilityGroups\$AG1Name"
Add-SqlAvailabilityDatabase –Path $agpath1 –Database $tmpDB1
#---------------------------------------------
#Create a Listener using Static IPs
#---------------------------------------------
$agpath1 = "SQLSERVER:\SQL\$Server1\default\AvailabilityGroups\$AG1Name"
$ag = Get-Item $agpath1; #Validate AG Path
New-SqlAvailabilityGroupListener -Name $AGListner1Name –Path $agpath1 –StaticIp $Listner1IP_Mask –Port $ListnerPort;

Thursday, April 30, 2015

Copy SharePoint views to other libraries with PowerShell

[CmdletBinding()]

Param
(
  [Parameter(Mandatory=$true,ValueFromPipeline=$true)][string]$WebURL,
  [Parameter(Mandatory=$true)][string]$SourceList,
  [Parameter(Mandatory=$true)][string]$SourceView,
  [Parameter(Mandatory=$false)][string]$NewViewName,
  [Parameter(Mandatory=$false)][string]$TargetURL,
  [Parameter(Mandatory=$false)][string]$IgnoreLibs,
  [Parameter(Mandatory=$false)][string]$AsDefault,
  [Parameter(Mandatory=$false)][string]$OutputPath,
  [Parameter(Mandatory=$false)][string]$SmtpServer,
  [Parameter(Mandatory=$false)][string]$EmailFrom,
  [Parameter(Mandatory=$false)][string]$EmailTo
)

Function Copy-SPView
{

  Write-Host &quot;Loading Sytem Modules &quot;
  Get-Module -listAvailable | import-module

  if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell -ErrorAction SilentlyContinue) -eq $null )
  {
    Write-Host &quot;Loading Sharepoint Module &quot;
    [System.Reflection.Assembly]::LoadWithPartialName(&quot;Microsoft.SharePoint&quot;)
    Add-PSSnapin -Name Microsoft.SharePoint.PowerShell

    if ( (Get-PSSnapin -Name Microsoft.SharePoint.PowerShell) -eq $null )
    {
      Write-Host &quot;Failed to load sharepoint snap-in. Could not proceed further, Aborting ...&quot;
      Exit
    }
  }

  Start-SPAssignment -Global

  $SPWeb  = Get-SPWeb -Identity $WebURL -ErrorAction SilentlyContinue
  $SPWebT = Get-SPWeb -Identity $TargetURL -ErrorAction SilentlyContinue

  $ignoreList = &quot;Customized Reports&quot;,&quot;Form Templates&quot;,&quot;Shared Documents&quot;,&quot;Site Assets&quot;,&quot;Site Pages&quot;,&quot;Style Library&quot;,&quot;Master Page Gallery&quot;,&quot;Picture&quot; + $SourceList + $IgnoreLibs

  if($SPWeb -eq $null){ Write-Host &quot;Unable to reach the provided URL, Aborting ...&quot; ;Exit }
  if( ($SPWeb.Lists.TryGetList($SourceList) ) -eq $Null){ Write-Host &quot;The list $SourceList is not availible, Aborting ...&quot;; Exit }
  if($AsDefault -ne $True){$AsDefault = $False}

  $SourceLists=$SPweb.lists[&quot;$SourceList&quot;]

  if( ($SourceLists.Views[$SourceView]) -eq $Null ){ Write-Host &quot;The view $SourceView does not exist, Aborting ...&quot;; Exit  }
  if($NewViewName -lt 1){ $NewViewName = $SourceView }

  # Go through each document library in the target site
  $listIds = @();
  $i = 0;

  if($SPWebT -ne $null)
  {
    $lists=$SPWebT.lists
  }
  else
  {
    $lists=$SPWeb.lists
  }

  while ($i -lt $lists.Count)
  {
    $list = $lists[$i]

    if($list.BaseType -eq &quot;DocumentLibrary&quot;)
    {
      if ($Ignorelist -contains $list.Title)
      {
        write-host $list &quot;is Ignored&quot; -foregroundcolor Yellow -backgroundcolor Black
      }
      else
      {
        $view = $list.Views[$NewViewName]
        if ($view -ne $null)
        {
          Write-Host &quot;Updating existing view&quot; -foregroundcolor Yellow -backgroundcolor Black

          $list.views.delete($view.ID)
          $list.update()
        }

        $Viewfields = $Sourcelists.Views[$SourceView].ViewFields.ToStringCollection()
        $viewRowLimit=&quot;100&quot;
        $viewPaged=$true
        $viewDefaultView=$AsDefault

        # Setting the Query for the View
        $viewQuery = $Sourcelists.Views[$SourceView].Query
        $viewName = $NewViewName

        # Finally – Provisioning the View

        try
        {
          $myListView = $list.Views.Add($viewName, $viewFields, $viewQuery, 100, $True, $False, &quot;HTML&quot;, $False)
        }
        catch
        {
          Write-Host &quot;Not all columns are availible in the target library&quot; -foregroundcolor Yellow
        }

        # You need to Update the View for changes made to the view
        # Updating the List is not enough
        $myListView.DefaultView = $AsDefault
        $myListView.Update()
        $list.Update()

        Write-Host &quot;$viewName added to Library $list&quot;
      }
    }
  $i = $i + 1
  }
$SPWeb.Dispose()
}

Copy-SPView ($WebURL,$SourceList,$SourceView,$NewViewName)

Using this script it’s possible to copy views from a source library to any target library.
This includes copying views to libraries in other site collections / web applications or even other SharePoint servers!

Summary of possible variables:

– WebURL
  URL of the source library
– SourceList
  Displayname of the source library what contains the view
– SourceView
  Name of the view that needs to be copied
– NewViewName
  Name of the view in the target libraries. (if left empty the source view name will be used.)
– TargetURL
URL of the target site / site collection of web application (If left empty the libraries in the WebURL are being
   updated)
– IgnoreLibs
  Name of the libraries that need to be ignored.
(The script contains a list of SharePoint Household Libraries
  that are ignored by default including the Source Library.)
  “Customized Reports”,”Form Templates”,”Shared Documents”,”Site Assets”,”Site Pages”,
  “Style Library”,”Master Page Gallery”,”Picture”

.Example 1
# This example copies the view to all document libraries within the source URL
# PS C:\> .\Copy-SPView.ps1 -WebURL <source URL> -SourceList <Your Source Library> -SourceView <Name of View>

.Example 2
# This example copies the view to all document libraries within the target URL.
# PS C:> .Copy-SPView.ps1 -WebURL <source URL> -SourceList <Your Source Library> -SourceView <Name of the View> -TargetURL “<Your target URL>”

.Example 3
# This example shows all possible variables that are currently working.
# PS C:> .Copy-SPView.ps1 -WebURL <source URL> -SourceList <Your Source Library> -SourceView <Name of the View> -TargetURL “<Your target URL>” -NewViewName “Rogier’s View” -IgnoreLibs “Shared Documents”

Please let me know if this was helpful

PowerShell Script to get all the Active Directory groups in your SharePoint Farm

At a client recently, I was tasked to create an inventory of all the Active Directory Groups that give access to a SharePoint site! I built it mostly from scratch, so here it is as well as some explanations to help you use it:

function WriteLogs ($message) {
    $message | Out-File $logfile -append
}

$logfile = "C:\ADGroupInventory\grouplist.txt"
Write-Host "Starting Group Script inventory"
$was = Get-SPWebApplication

foreach ($wa in $was)
 {       
  $webappUrl = $wa.url
  Write-Host "Starting to look in $webappUrl"
  $spWebApp = Get-SPWebApplication $wa.url       
  foreach($site in $spWebApp.Sites)
  {
    $siteurl = $site.url
    Write-Host "Going into SiteCollection $siteurl"
    $group = $site.RootWeb.SiteUsers
    foreach ($grp in $group)
    {
     # Ensure the item is a domain group
     if($grp.IsDomainGroup -eq "True")
     {
      $groupname = $grp.name
      WriteLogs "$groupname"
     }
    }
  }   
 }

* First of all, change the $logfile variable to a folder that exists to make sure the logs work.

* Second, in the Central Administration, give yourself "Full Control" in the Web Application User Policy. This will make sure that you won't have any access denied when you go through each and every site collection in your farm.

* Afterwards, open SharePoint Management Shell as an Administrator, and run the script. Depending of the size of you farm, it shouldn't take too long, and you should see progress of every site being scanned on the screen. At the end, you will have a text file looking like this:


You will notice in the screenshot that some group names are repeated, as well as some of them are in capital and some of them are lowercase.

* So, I used NotePad++ to get all the unique group names!
First of all, go in Edit > Convert Case to > Upercase!
You will notice in the screenshot that some group names are repeated, as well as some of them are in capital and some of them are lowercase.

To get unique lines, you will need the TextFX plugin. This used to be included in older versions of Notepad++, but if you have a newer version, you can add it from the menu by going to Plugins -> Plugin Manager -> Show Plugin Manager -> Available tab -> TextFX -> Install. In some cases it may also be called TextFX Characters, but this is the same thing.

After the plugin is installed, go in TestFX Tools and check the "sort ascending" and "sort outputs only UNIQUE" lines. Afterwards, click the "Sort lines case insensitive at column". (make sure that you do Ctrl+a in the file to select all the lines before clicking).

Now, your Notepad++ will only show the unique group names in your SharePoint Farm!

Drop a comment if this helped!

Move SharePoint 2013 Search Index Location

#-----------------------------------------------------------------------------
# Name:               Move-SPEnterpriseSearchIndex.ps1 
# Description:      This script will move the SharePoint 2013 Search Index               
# Usage:               Run the function with the 3 required Parameters 
#-----------------------------------------------------------------------------

function Move-SPEnterpriseSearchIndex($SearchServiceName,$Server,$IndexLocation){
    Add-PSSnapin Microsoft.SharePoint.PowerShell -ea 0;
    #Gets the Search Service Application
    $SSA = Get-SPServiceApplication -Name $SearchServiceName;
    if (!$?){throw "Cant find a Search Service Application: `"$SearchServiceName`"";}
    #Gets the Search Service Instance on the Specified Server
    $Instance = Get-SPEnterpriseSearchServiceInstance -Identity $Server;
    if (!$?){throw "Cant find a Search Service Instance on Server: `"$Server`"";}
    #Gets the current Search Topology
    $Current = Get-SPEnterpriseSearchTopology -SearchApplication $SSA -Active;
    if (!$?){throw "There is no Active Topology, you can try removing the `"-Active`" from the line above in the script";}
    #Creates a Copy of the current Search Topology
    $Clone = New-SPEnterpriseSearchTopology -Clone -SearchApplication $SSA -SearchTopology $Current;
    #Adds a new Index Component with the new Index Location
    New-SPEnterpriseSearchIndexComponent -SearchTopology $Clone -IndexPartition 0 -SearchServiceInstance $Instance -RootDirectory $IndexLocation | Out-Null;
    if (!$?){throw "Make sure that Index Location `"$IndexLocation`" exists on Server: `"$Server`"";}
    #Sets our new Search Topology as Active
    Set-SPEnterpriseSearchTopology -Identity $Clone;
    #Removes the old Search Topology
    Remove-SPEnterpriseSearchTopology -Identity $Current -Confirm:$false;
    #Now we need to remove the extra Index Component
    #Gets the Search Topology
    $Current = Get-SPEnterpriseSearchTopology -SearchApplication $SSA -Active;
    #Creates a copy of the current Search Topology
    $Clone=New-SPEnterpriseSearchTopology -Clone -SearchApplication $SSA -SearchTopology $Current;
    #Removes the old Index Component from the Search Topology
    Get-SPEnterpriseSearchComponent -SearchTopology $Clone | ? {($_.GetType().Name -eq "IndexComponent") -and ($_.ServerName -eq $($Instance.Server.Address)) -and ($_.RootDirectory -ne $IndexLocation)} | Remove-SPEnterpriseSearchComponent -SearchTopology $Clone -Confirm:$false;
    #Sets our new Search Topology as Active
    Set-SPEnterpriseSearchTopology -Identity $Clone;
    #Removes the old Search Topology
    Remove-SPEnterpriseSearchTopology -Identity $Current -Confirm:$False;
    Write-Host "The Index has been moved to $IndexLocation on $Server"
    Write-Host "This will not remove the data from the old index location. You will have to do that manually :)"
}


Move-SPEnterpriseSearchIndex -SearchServiceName "Search Service Application" -Server "SP2013-WFE" -IndexLocation "C:\Index"

 SharePoint 2013 places the Search index in the C: by default. There are many reasons why you would want to move the index to a different places.
This script will take three parameters, the Search Service Name, the Server Name and Index Location.  There is an example on the bottom of the script.

Wednesday, April 29, 2015

Repair corrupted SharePoint 2013 Distributed Cache cluster

Before you begin, please check if your SharePoint farm SQL servers are using Dynamic memory on ESX or Hyper-V. If yes - Turn it OFF! And check if it helped.

Launch AppFabric PowerShell console and execute:
Use-CacheCluster
Get-CacheHost
Check if Cluster is 'UP'
If not then:
Start-CacheHost –ComputerName [yourServerName] –CachePort 22233
then get your SharePoint farm GUID
$spFarm=[Microsoft.SharePoint.Administration.SPfarm]::Local
$spFarm.Id
Export your current cluster configuration as backup. For reference and just in case..
Export-CacheClusterConfig c:\Backup.xml
Replace text in XML bellow:
YOUR-FARM-ID to your farm GUID,
CONTOSO\ClusterServiceAccount to your cluster service account,
SERVER1.COM to your cluster host.
Copy host section if you have multiple cluster hosts and change server name.
Change hostid like in Backup.xml and refer to other configuration details in this file.
<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <configSections>
        <section name="dataCache" type="Microsoft.ApplicationServer.Caching.DataCacheSection, Microsoft.ApplicationServer.Caching.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
    </configSections>
    <dataCache size="Medium">
        <caches partitionCount="256">
            <cache consistency="StrongConsistency" name="DistributedAccessCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedActivityFeedCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedActivityFeedLMTCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="None" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedBouncerCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedDefaultCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedLogonTokenCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedSearchCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedSecurityTrimmingCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedServerToAppServerAccessTokenCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
            <cache consistency="StrongConsistency" name="DistributedViewStateCache_YOUR-FARM-ID"
                minSecondaries="0">
                <policy>
                    <eviction type="Lru" />
                    <expiration defaultTTL="10" isExpirable="true" />
                </policy>
            </cache>
        </caches>
        <hosts>
            <host replicationPort="22236" arbitrationPort="22235" clusterPort="22234"
                hostId="280822625" size="1229" leadHost="true" account="CONTOSO\ClusterServiceAccount"
                cacheHostName="AppFabricCachingService" name="SERVER1.COM"
                cachePort="22233" />
        </hosts>
        <advancedProperties>
            <partitionStoreConnectionSettings leadHostManagement="false" />
            <securityProperties>
                <authorization>
                    <allow users="WSS_ADMIN_WPG" />
                    <allow users="WSS_WPG" />
                </authorization>
            </securityProperties>
        </advancedProperties>
        <deploymentSettings>
            <deploymentMode value="RoutingClient" />
        </deploymentSettings>
    </dataCache>
</configuration>

Save it to file c:\NewConfig.xml
Then stop cluster, import edited config file to cluster configuration and start it again:
Stop-CacheCluster
Import-CacheClusterConfig C:\NewConfig.xml
Start-CacheCluster
Then after several minutes try
Get-Cache
You should get:
CacheName            [Host]                      Regions
———————–
 default
 DistributedAccessCache_
 DistributedActivityFeedCache_
 DistributedActivityFeedLMTCache_
 .....