The best methods to remove a server from the farm are to either use the psconfig wizard or run Disconnect-SPconfigurationDatabase
If that has not happened and someone deleted the VM without first disconnecting the vm from the farm, please recall that there is the off chance that the vm, at one point, may have participated in the distributed cache cluster. And, if that is the case, then you need to run the following, taking into account that the following assumes there were two servers that had been erroneously removed, by having the VM deleted before being removed from SharePoint. You might only need one instantiation of the serviceInstance and then call the delete method. In my case I had two servers named servername and server2name.
In that case run this code
$SPFarm = Get-SPFarm $cacheClusterName = "SPDistributedCacheCluster_" + $SPFarm.Id.ToString() $cacheClusterName SPDistributedCacheCluster_0952ce0a-1ab3-4251-a6fd-52f7878c6c4a $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 "servername"} $serviceInstance.Delete() $serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq "server2name"} $serviceInstance.Delete() $cacheClusterInfo.CacheHostsInfoCollection
After you run that, ServerName and Server2Name servers will still be present on the servers in the farm page but now when you click on it you will not get the CacheHostInfo Null message and it will disappear off the servers in the farm page and if you run )get-spfarm).servers or get-spserver you will not get the servername and server2name servers in the output
Line 10 and 11 are not needed if you only have one server to remove. For example, if you had a server named mdcpappshr01wv, you could replace line 8 with this
$serviceInstance = Get-SPServiceInstance | ? {($_.Service.Tostring()) -eq $instanceName -and ($_.Server.Name) -eq "mdcpappshr01wv"}
and then delete line 10 and 11
you would still call the .delete() method against the serviceInstance variable.
One other thing to keep in mind about these steps. They work great for cachehostinfo is null when troubleshooting a different, issue, unrelated to having servers on the servers in farm page.
Say for example that you are just getting the cachehostinfo is null when working with distributed cache.
run the above for every server in your farm and remove distributed cache service instance from each server, then add the service instance back to one server and least privilege the service then add the service back to the other servers as you see fit for your farm and for their roles.