使用 PowerShell 从 Service Fabric 群集中删除应用程序

此示例脚本删除了正在运行的 Service Fabric 应用程序实例,并从群集中取消注册了应用程序类型和版本。 删除应用程序实例时也会删除与该应用程序关联的所有正在运行的服务实例。 根据需要自定义参数。

必要时,使用 Service Fabric SDK 安装 Service Fabric PowerShell 模块。

示例脚本

# 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

脚本说明

此脚本使用以下命令。 表中的每条命令均链接到特定于命令的文档。

命令 说明
Remove-ServiceFabricApplication 从群集中删除正在运行的 Service Fabric 应用程序实例。
Unregister-ServiceFabricApplicationType 从群集中注销 Service Fabric 应用程序类型和版本。

后续步骤

有关 Service Fabric PowerShell 模块的详细信息,请参阅 Azure PowerShell 文档

可以在 Azure PowerShell 示例中找到 Azure Service Fabric 的其他 PowerShell 示例。