【发布时间】:2018-11-28 21:52:48
【问题描述】:
剧透:我是 Azure 和 Azure Powershell 的新手。
我开始学习 Azure 和 Azure Powershell,我目前的自学练习是编写一个脚本,用于检查 Azure 中是否存在特定资源组。如果此特定资源组不存在,则创建一个。于是我开始写这个脚本:
# Exit on error
$ErrorActionPreference = "Stop"
# Import module for Azure Rm
Import-Module AzureRM
# Connect with Azure
Connect-AzureRmAccount
# Define name of Resource group we want to create
$ResourceGroupTest = "ResourceGroupForStorageAccount"
# Check if ResourceGroup exists
Get-AzureRmResourceGroup -Name $ResourceGroupTest -ErrorVariable $NotPresent -ErrorAction SilentlyContinue
Write-Host "Start to check if Resource group '$($ResourceGroupTest)' exists..."
if ($NotPresent) {
Write-Host "Resource group with name '$($ResourceGroupTest)' does not exist."
# Create resource group
New-AzureRmResourceGroup -Name $ResourceGroupTest -Location "West Europe" -Verbose
} else {
Write-Host "Found Resource group with name '$($ResourceGroupTest)'."
}
现在,当我运行这个脚本时,我得到了这样的输出:
Start to check if Resource group 'ResourceGroupForStorageAccount' exists...
Found Resource group with name 'ResourceGroupForStorageAccount'.
Account SubscriptionName Tenant ...
------- ---------------- -------- ...
my.email@host.com Some subscription ...
但我在 Azure RM 门户的资源组列表中找不到这个名为 ResourceGroupForStorageAccount 的新创建资源组。
我的问题在哪里?
【问题讨论】:
-
嗨,克里斯蒂安,你的问题有什么更新吗?对你有用吗?
-
@IvanYang 第一次阅读您的答案后,我在脚本中更改了它并重新运行它,但没有看到任何更改。现在,几天后,我再次尝试,它成功了,现在我可以在我的 Azure 门户中看到资源组。所以,谢谢你的回答。
-
资源组创建后过段时间看不到就太奇怪了,不过能用就太高兴了:)。
标签: azure powershell azure-powershell azure-resource-group