使用 PowerShell 管理 Azure Stack Hub 中的订阅、计划和套餐

你可以使用 PowerShell,通过使用套餐、计划和订阅来配置并交付服务。 有关在 Azure Stack Hub 上使用 PowerShell 进行设置的说明,请参阅安装适用于 Azure Stack Hub 的 PowerShell Az 模块。 若要了解如何使用 PowerShell 连接到 Azure Stack Hub,请参阅使用 PowerShell 连接到 Azure Stack Hub

在开始之前,请验证是否已加载 Azure Stack Hub PowerShell 模块。 在 PowerShell 控制台中,键入 Import-Module AzureStack

创建计划

在创建计划时,需要有配额。 你可以使用现有的配额,或者也可以创建新配额。 例如,若要创建存储、计算和网络配额,可以使用 New-AzsStorageQuotaNew-AzsComputeQuotaNew-AzsNetworkQuota cmdlet:

$serviceQuotas  = @()
$serviceQuotas += (New-AzsStorageQuota -Name "Example storage quota with defaults").Id
$serviceQuotas += (New-AzsComputeQuota -Name "Example compute quota with defaults").Id
$serviceQuotas += (New-AzsNetworkQuota -Name "Example network quota with defaults").Id

若要创建或更新基本计划或加载项计划,请使用 New-AzsPlan

$testPlan = New-AzsPlan -Name "testplan" -ResourceGroupName "testrg" -QuotaIds $serviceQuotas -Description "Test plan"

创建产品

若要创建套餐,请使用 New-AzsOffer

New-AzsOffer -Name "testoffer" -ResourceGroupName "testrg" -BasePlanIds @($testPlan.Id)

在具有了套餐之后,你可以将计划添加到该套餐。 请使用 Add-AzsPlanToOffer。 -PlanLinkType 参数用于区分计划类型。

Add-AzsPlanToOffer -PlanName "addonplan" -PlanLinkType Addon -OfferName "testoffer" -ResourceGroupName "testrg" -MaxAcquisitionCount 18

如果需要更改套餐的状态,请使用 Set-AzsOffer cmdlet。

$offer = Get-AzsAdminManagedOffer -Name "testoffer" -ResourceGroupName "testrg"
$offer.state = "Public"
$offer | Set-AzsOffer -Confirm:$false

创建对套餐的订阅

创建某个套餐后,用户需要订阅此套餐才能使用此套餐。 用户可通过两种方式订阅套餐:

  • 作为云操作员,你可以为用户创建订阅。 创建的订阅可用于公共和专用套餐。
  • 作为用户,你可以订阅公共套餐。

若要以云操作员身份为用户创建订阅,请使用 New-AzsUserSubscription

New-AzsUserSubscription -Owner "user@contoso.com" -DisplayName "User subscription" -OfferId "/subscriptions/<Subscription ID>/resourceGroups/testrg/providers/Microsoft.Subscriptions.Admin/offers/testoffer"

若要以用户身份订阅公共套餐,请使用 New-AzsSubscriptionNew-AzsSubscription 需要连接到用户 Azure 资源管理器环境。 请使用使用 PowerShell 连接到 Azure Stack Hub 中的步骤,但使用用户 Azure 资源管理器终结点。 例如,Add-AzEnvironment -Name "AzureStackUser" -ArmEndpoint "https://management.local.azurestack.external"

$testOffer = Get-AzsOffer | Where-Object Name -eq "testoffer"
New-AzsSubscription -OfferId $testOffer.Id -DisplayName "My subscription"

删除配额、计划、套餐和订阅

PowerShell 有配套的 cmdlet 可用于删除 Azure Stack Hub 配额、计划、套餐和订阅。 下面显示了每种删除操作的示例。

请使用 Remove-AzsUserSubscription 从套餐中删除订阅。

Remove-AzsUserSubscription -TargetSubscriptionId "c90173b1-de7a-4b1d-8600-b8325ca1eab1e"

若要从套餐中删除计划,请使用 Remove-AzsPlanFromOffer

Remove-AzsPlanFromOffer -PlanName "addonplan" -PlanLinkType Addon -OfferName "testoffer" -ResourceGroupName "testrg"
Remove-AzsPlanFromOffer -PlanName "testplan" -PlanLinkType Base -OfferName "testoffer" -ResourceGroupName "testrg"

请使用 Remove-AzsPla 来删除计划。

Remove-AzsPlan -Name "testplan" -ResourceGroupName "testrg"

请使用 Remove-AzsOffer 来删除套餐。

Remove-AzsOffer -Name "testoffer" -ResourceGroupName "testrg"

若要删除配额,请使用 Remove-AzsStorageQuotaRemove-AzsComputeQuotaRemove-AzsNetworkQuota

Remove-AzsStorageQuota -Name "Example storage quota with defaults"
Remove-AzsComputeQuota -Name "Example compute quota with defaults"
Remove-AzsNetworkQuota -Name "Example network quota with defaults"

后续步骤