Remove an application from a Service Fabric cluster using PowerShell

This sample script deletes a running Service Fabric application instance and unregisters an application type and version from the cluster. Deleting the application instance also deletes all the running service instances associated with that application. Customize the parameters as needed.

If needed, install the Service Fabric PowerShell module with the Service Fabric SDK.

Sample script

# Variables
$endpoint = 'mysftestcluster.southcentralus.cloudapp.azure.com:19000'
$thumbprint = '2779F0BB9A969FB88E04915FFE7955D0389DA7AF'
$packagepath="C:\Users\sfuser\Documents\Visual Studio 2017\Projects\MyApplication\MyApplication\pkg\Release"

# Connect to the cluster using a client certificate.
Connect-ServiceFabricCluster -ConnectionEndpoint $endpoint `
          -KeepAliveIntervalInSec 10 `
          -X509Credential -ServerCertThumbprint $thumbprint `
          -FindType FindByThumbprint -FindValue $thumbprint `
          -StoreLocation CurrentUser -StoreName My

# Remove an application instance
Remove-ServiceFabricApplication -ApplicationName fabric:/MyApplication

# Unregister the application type
Unregister-ServiceFabricApplicationType -ApplicationTypeName MyApplicationType -ApplicationTypeVersion 1.0.0

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
Remove-ServiceFabricApplication Removes a running Service Fabric application instance from the cluster.
Unregister-ServiceFabricApplicationType Unregisters a Service Fabric application type and version from the cluster.

Next steps

For more information on the Service Fabric PowerShell module, see Azure PowerShell documentation.

Additional PowerShell samples for Azure Service Fabric can be found in the Azure PowerShell samples.