1st run this script to clear all the running instances of the DC
$instanceName ="SPDistributedCacheService Name=AppFabricCachingService"
$serviceInstance = Get-SPServiceInstance | ? {($_.service.tostring()) -eq $instanceName -and ($_.server.name) -eq $env:computername}
If($serviceInstance -ne $null){ $serviceInstance.Delete()}
Now run this command and it should not show any thing
Get-SPServiceInstance | ? {($_.service.tostring()) -eq "SPDistributedCacheService Name=AppFabricCachingService"} | select Server, Status
Now make sure that appfabric service is stoped and start type disabled. Check it from services console.
Finally Run the
Add-SPDistributedCacheServiceInstance
Wait for minutes now check the status again.
Use-CacheCluster
Get-CacheHost
Update:
If above script is giving you the error of null valued expression you can use the modified commands as below and it works successfully:
$serviceInstance = Get-SPServiceInstance | Where-Object {
$_.TypeName -like "*Distributed Cache*"}
if ($serviceInstance -ne $null) {
$serviceInstance.Delete()
} else {
Write-Host "No Distributed Cache service instance found on this server."
}
After this, run:
Add-SPDistributedCacheSericeInstance
Wait for 2-3 minutes.
Here we go and the service has been started successfully.