使用 Powershell 从 Service Fabric 群集中删除应用程序Remove an application from a Service Fabric cluster using Powershell

此示例脚本删除了正在运行的 Service Fabric 应用程序实例,并从群集中取消注册了应用程序类型和版本。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.

必要时,使用 Service Fabric SDK 安装 Service Fabric PowerShell 模块。If needed, install the Service Fabric PowerShell module with the Service Fabric SDK.

示例脚本Sample script

# Variables
$endpoint = 'mysftestcluster.chinaeast.cloudapp.chinacloudapi.cn: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.

CommandCommand 说明Notes
Remove-ServiceFabricApplicationRemove-ServiceFabricApplication 从群集中删除正在运行的 Service Fabric 应用程序实例。Removes a running Service Fabric application instance from the cluster.
Unregister-ServiceFabricApplicationTypeUnregister-ServiceFabricApplicationType 从群集中注销 Service Fabric 应用程序类型和版本。Unregisters a Service Fabric application type and version from the cluster.

后续步骤Next steps

有关 Service Fabric PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档For more information on the Service Fabric PowerShell module, see Azure PowerShell documentation.

可以在 Azure PowerShell 示例中找到 Azure Service Fabric 的其他 Powershell 示例。Additional Powershell samples for Azure Service Fabric can be found in the Azure PowerShell samples.