使用 PowerShell 管理 Azure Stack Hub 中的订阅、计划和套餐Use PowerShell to manage subscriptions, plans, and offers in Azure Stack Hub

你可以使用 PowerShell,通过使用套餐、计划和订阅来配置并交付服务。You can use PowerShell to configure and deliver services by using offers, plans, and subscriptions. 有关在 Azure Stack Hub 上使用 PowerShell 进行设置的说明,请参阅安装适用于 Azure Stack Hub 的 PowerShell Az 模块For instructions on getting set up with PowerShell on Azure Stack Hub, see Install PowerShell Az module for Azure Stack Hub. 若要了解如何使用 PowerShell 连接到 Azure Stack Hub,请参阅使用 PowerShell 连接到 Azure Stack HubFor information on connecting to Azure Stack Hub using PowerShell, see Connect to Azure Stack Hub with PowerShell.

在开始之前,请验证是否已加载 Azure Stack Hub PowerShell 模块。Before you begin, verify the Azure Stack Hub PowerShell module is loaded. 在 PowerShell 控制台中,键入 Import-Module AzureStackIn a PowerShell console, type Import-Module AzureStack.

创建计划Create a plan

在创建计划时,需要有配额。Quotas are required when creating a plan. 你可以使用现有的配额,或者也可以创建新配额。You can use an existing quotas or create new quotas. 例如,若要创建存储、计算和网络配额,可以使用 New-AzsStorageQuotaNew-AzsComputeQuotaNew-AzsNetworkQuota cmdlet:For example, to create a storage, compute and network quota, you can use the New-AzsStorageQuota, New-AzsComputeQuota, and New-AzsNetworkQuota cmdlets:

$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-AzsPlanTo create or update a base or add-on plan, use New-AzsPlan.

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

创建产品Create an offer

若要创建套餐,请使用 New-AzsOfferTo create an offer, use New-AzsOffer.

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

在具有了套餐之后,你可以将计划添加到该套餐。Once you have an offer, you can add plans to the offer. 请使用 Add-AzsPlanToOfferUse Add-AzsPlanToOffer. -PlanLinkType 参数用于区分计划类型。The -PlanLinkType parameter distinguishes the plan type.

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

如果需要更改套餐的状态,请使用 Set-AzsOffer cmdlet。If you want to change the state of an offer, use the Set-AzsOffer cmdlet.

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

创建对套餐的订阅Create subscription to an offer

创建某个套餐后,用户需要订阅此套餐才能使用此套餐。After you create an offer, users need a subscription to that offer before they can use it. 用户可通过两种方式订阅套餐:There are two ways that users can subscribe to an offer:

  • 作为云操作员,你可以为用户创建订阅。As a cloud operator, you can create a subscription for a user. 创建的订阅可用于公共和专用套餐。Subscriptions you create can be for both public and private offers.
  • 作为用户,你可以订阅公共套餐。As a user, you can subscribe to a public offer.

若要以云操作员身份为用户创建订阅,请使用 New-AzsUserSubscriptionTo create a subscription for a user as a cloud operator, use New-AzsUserSubscription.

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

若要以用户身份订阅公共套餐,请使用 New-AzsSubscriptionTo subscribe to a public offer as a user, use New-AzsSubscription. New-AzsSubscription 需要连接到用户 Azure 资源管理器环境。New-AzsSubscription requires connection to the user Azure Resource Manager environment. 请使用使用 PowerShell 连接到 Azure Stack Hub 中的步骤,但使用用户 Azure 资源管理器终结点。Use the steps in Connect to Azure Stack Hub with PowerShell but use the user Azure Resource Manager endpoint. 例如,Add-AzEnvironment -Name "AzureStackUser" -ArmEndpoint "https://management.local.azurestack.external"For example, Add-AzEnvironment -Name "AzureStackUser" -ArmEndpoint "https://management.local.azurestack.external".

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

删除配额、计划、套餐和订阅Delete quotas, plans, offers, and subscriptions

PowerShell 有配套的 cmdlet 可用于删除 Azure Stack Hub 配额、计划、套餐和订阅。There are companion PowerShell cmdlets to delete Azure Stack Hub quotas, plans, offers, and subscriptions. 下面显示了每种删除操作的示例。The following show examples for each.

请使用 Remove-AzsUserSubscription 从套餐中删除订阅。Use Remove-AzsUserSubscription to remove a subscription from an offer.

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

若要从套餐中删除计划,请使用 Remove-AzsPlanFromOfferTo remove a plan from an offer, use Remove-AzsPlanFromOffer.

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

请使用 Remove-AzsPla 来删除计划。Use Remove-AzsPlan to remove a plan.

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

请使用 Remove-AzsOffer 来删除套餐。Use Remove-AzsOffer to remove an offer.

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

若要删除配额,请使用 Remove-AzsStorageQuotaRemove-AzsComputeQuotaRemove-AzsNetworkQuotaTo remove quotas, use Remove-AzsStorageQuota, Remove-AzsComputeQuota, Remove-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"

后续步骤Next steps