如何使用 PowerShell 建立新的 Azure 資源組?


Azure 資源組是儲存虛擬機器、儲存、IP 地址等資源的容器。要建立新的 Azure 資源組,我們需要使用 New-AZResourceGroup 命令。

要使用此 cmdlet,首先需要連線到 Azure 賬戶,然後如果你想要為特定訂閱建立一個資源組,則需要選擇該訂閱。

要建立新的資源組,你需要資源組的位置。以下程式碼首先會連線到你的 Azure 賬戶,選擇 Azure 訂閱,然後建立一個新的資源組。

示例

$ErrorActionPreference = "Stop"
Connect-AzAccount
Set-AzContext -SubscriptionName 'Enter your subscription name here'
New-AzResourceGroup -Name 'TestRG' -Location 'Central US' -Tag @{'RG'='APP'}

輸出

ResourceGroupName : TestRG
Location          : centralus
ProvisioningState : Succeeded
Tags              :
                    Name  Value
                    ====  =====
                    RG    APP

ResourceId        : /subscriptions/8ac5a3e4-390b-9034-8ad5-3585aseesasac/resourceGroups/TestRG

上述命令將在美國中部位置建立 Azure 資源組,關聯標籤‘RG’及其值‘APP’

更新日期:2021-4-12

2K+ 瀏覽量

開啟您的 職業

透過完成課程獲得認證

立即開始
廣告
© . All rights reserved.