Pet*_*lka 15 powershell azure-powershell azure-resource-manager
我正在尝试验证ResourceGroup是否存在所以我认为以下代码应返回true或false,但它不输出任何内容.
$RSGtest = Find-AzureRmResource | Format-List ResourceGroupName | get-unique
$RSGtest -Match "$myResourceGroupName"
为什么我没有得到任何输出?
Mar*_*ndl 23
有一个Get-AzureRmResourceGroup cmdlet:
Get-AzureRmResourceGroup -Name $myResourceGroupName -ErrorVariable notPresent -ErrorAction SilentlyContinue
if ($notPresent)
{
    # ResourceGroup doesn't exist
}
else
{
    # ResourceGroup exist
}
尝试这个
$ResourceGroupName = Read-Host "Resource group name"
Find-AzureRmResourceGroup | where {$_.name -EQ $ResourceGroupName}