使用 PowerShell 管理 Azure Stack 中心的订阅、计划和产品/服务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. 使用 PowerShell。using PowerShell. 有关在 Azure Stack 集线器上设置 PowerShell 的说明,请参阅 安装适用于 Azure Stack 中心的 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 集线器的信息,请参阅 使用 Powershell 连接到 Azure Stack 中心For information on connecting to Azure Stack Hub using PowerShell, see Connect to Azure Stack Hub with PowerShell.

在开始之前,请验证是否已加载 Azure Stack 集线器 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. 例如,若要创建存储、计算和网络配额,可使用 AzsStorageQuotaAzsComputeQuotaAzsNetworkQuota 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

若要创建或更新基础计划或外接程序计划,请使用 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

若要创建产品/服务,请使用 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. 请使用 AzsPlanToOfferUse Add-AzsPlanToOffer. -PlanLinkType 参数用于区分计划类型。The -PlanLinkType parameter distinguishes the plan type.

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

若要更改产品/服务的状态,请使用 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.

若要为用户创建作为云操作员的订阅,请使用 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"

若要以用户身份订阅公共产品/服务,请使用 AzsSubscriptionTo subscribe to a public offer as a user, use New-AzsSubscription. AzsSubscription 要求连接到用户 Azure 资源管理器环境。New-AzsSubscription requires connection to the user Azure Resource Manager environment. 使用 通过 PowerShell 连接到 Azure Stack 集线器 中的步骤,但使用用户 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 集线器配额、计划、产品和订阅。There are companion PowerShell cmdlets to delete Azure Stack Hub quotas, plans, offers, and subscriptions. 下面显示了每个的示例。The following show examples for each.

使用 AzsUserSubscription 从产品/服务中删除订阅。Use Remove-AzsUserSubscription to remove a subscription from an offer.

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

若要从产品/服务中删除计划,请使用 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"

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

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

使用 AzsOffer 删除产品/服务。Use Remove-AzsOffer to remove an offer.

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

若要删除配额,请使用 AzsStorageQuotaAzsComputeQuotaAzsNetworkQuotaTo 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