Blog Image

PowerShell

SharePoint Powershell Commands

GoSharePoint Website
Documentation Blog

This blog is based on SharePoint 2013 PowerShell Commands. Please visit my other blog which contains SharePoint Documentation.

UnProvision Distributed Cache Instance

Distributed Cache Posted on Tue, June 28, 2016 05:03:27

$instanceName = “SPDistributedCacheService Name = AppFabricCachingService”

$serviceInstance = Get-SPServiceInstance | ? {( $_.service.tostring()) –eq $instanceName –and ($_.server.name) –eq $env:computername }

$serviceInstance.UnProvision()



Repair DistributedCache

Distributed Cache Posted on Tue, June 28, 2016 05:03:01

$SPFarm = Get-SPFarm

$cacheClusterName = “SPDistributedCacheCluster_” + $SPFarm.Id.ToString()

$cacheClusterManager = [Microsoft.SharePoint.DistributedCaching.Utilities.SPDistributedCacheClusterInfoManager]::Local

$cacheClusterInfo = $cacheClusterManager.GetSPDistributedCacheClusterInfo($cacheClusterName);

$instanceName =”SPDistributedCacheService Name=AppFabricCachingService”

$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq $env:computername}

if([System.String]::IsNullOrEmpty($cacheClusterInfo.CacheHostsInfoCollection))

{

#here’s the key. we can’t provision, unprovision, start, or stop a Cache Service because we still have a Cache Service that have no server attached

$serviceInstance.Delete()

Add-SPDistributedCacheServiceInstance

$cacheClusterInfo.CacheHostsInfoCollection

}



Provision Distributed Cache Instance

Distributed Cache Posted on Tue, June 28, 2016 05:00:57

$instanceName = “SPDistributedCacheService Name = AppFabricCachingService”

$serviceInstance = Get-SPServiceInstance | ? {( $_.service.tostring()) –eq $instanceName –and ($_.server.name) –eq $env:computername }

$serviceInstance.Provision()



Get DistributedCache ID Status

Distributed Cache Posted on Tue, June 28, 2016 04:59:49

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

$ddc = Get-SPServiceInstance | where {$_.TypeName -eq “Distributed Cache”}

$ddc



Delete Distributed Cache Instance

Distributed Cache Posted on Tue, June 28, 2016 04:59:12

$instanceName= “SPDistributedCacheService Name=AppFabricCachingService”

$serviceInstance= Get-SpServiceInstance | ? {(_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq “<server name>”}

$serviceInstance.Delete()



Delete Distributed Cache Instance using GUID

Distributed Cache Posted on Tue, June 28, 2016 04:58:23

$Guid = “xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx”

$s = Get-SPServiceInstance $Guid

$s.delete()



Change Service Account using AppFabricCachingService

Distributed Cache Posted on Tue, June 28, 2016 04:56:13

$farm = Get-SPFarm

$cacheService = $farm.Services | where {$_.Name -eq “AppFabricCachingService”}

$accnt = Get-SPManagedAccount -Identity AD\xxx_SP_Farm

$cacheService.ProcessIdentity.CurrentIdentityType = “SpecificUser”

$cacheService.ProcessIdentity.ManagedAccount = $accnt

$cacheService.ProcessIdentity.Update()

$cacheService.ProcessIdentity.Deploy()



Add Distributed Cache Service Instance

Distributed Cache Posted on Tue, June 28, 2016 04:54:43

#Allows to use SharePoint cmdlets from inside the Windows PowerShell command window

If ((Get-PsSnapin |?{$_.Name -eq “Microsoft.SharePoint.PowerShell”})-eq $null)

{

Add-PsSnapin Microsoft.SharePoint.PowerShell | Out-Null

}

Add-SPDistributedCacheServiceInstance