在 Azure Stack Hub 中使用 PowerShell 來管理訂用帳戶、方案和供應項目

您可以使用 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-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"

後續步驟