共用方式為


使用 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 Resource Manager 環境。 使用 使用 PowerShell 連線至 Azure Stack Hub 中的步驟,但使用使用者 Azure Resource Manager 端點。 例如,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-AzsPlan 來移除方案。

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

使用 Remove-AzsOffer 移除方案。

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

若要移除配額,請使用 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"

後續步驟