如何使用 PowerShell 创建新的 Azure 资源组?

powershellmicrosoft technologiessoftware & coding

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"。


相关文章