Few days back i was working on scenario where I was unable to delete the application and service from Azure Service fabric explorer and PowerShell. By looking at the application state in Service Fabric Explorer the application was in deleting state.
Executing the PowerShell command left out with the following error:
At this scenario, there are PowerShell cmdlet switches which play a vital role and can help to mitigate the issue. I have tried using -ForceRemove switch. The following cmdlet helps me to delete all application that are distributed across multiple nodes.
There might be situation where -Force switch could also fail. In that scenario try with
1) Move the Cluster Manager primary to another node and try to remove the app again:
a) Move-ServiceFabricPrimaryReplica -PartitionId [Cluster Manager System Service Partition Id] -ServiceName fabric:/System/ClusterManagerService
b) Remove-ServiceFabricApplication -ApplicationName fabric:/voting -Force -ForceRemove
2) If it still doesn't work due to stuck services or PLB affinity, try to move the primary for each partition of NamingService and try again.
There might also a scenario that the issue is happening with only one service distributed in multiple nodes instead of the whole application. Then use the below script which is like the one for application but with a little change which will only delete a specific Service.