2017-03-16 113 views
0

创建一个新的资源组,我需要建立一个循环,如果资源组名称采取或不,如果没有创建该名称的新资源组,将检查。创建一个循环,在PowerShell中

这是我曾经尝试并完成这个代码

do 
{ 
    $rg = Read-Host -Prompt "What would you like to name the new Resource Group" 
    if (!(Get-AzureRmResourceGroup -ResourceGroupName $rg -ErrorAction Ignore)) 
    { 
     New-AzureRmResourceGroup -ResourceGroupName $rg -Location "West Europe" 
    } 
    else { 
     $rg = Read-Host -Prompt "Resouce Group name not available, please select another" 
     New-AzureRmResourceGroup -ResourceGroupName $rg -Location "West Europe" 
    } 

} 
while (!(Get-AzureRmResourceGroup -ResourceGroupName $rg -ErrorAction Ignore)) 

回答

0

你说什么:“我希望用户输入一个数字,并保持如果直到他们进入事> 10进入”。

您编码什么:“输入一个数字,如果测试是< 10,并再次提示不要测试这一块,它没有去测试它现在圈了这一切。”

do 
{ 
    # coming round from a previous loop, $num exists, indicating this is a retry. 
    if ($null -ne $num) { Write-Host "Sorry, try again" } 

    [int]$num = Read-Host "Enter a number" 

} until ($num -gt 10) 
+0

感谢这就是我一直在寻找的东西,我看到我现在出错了 – lmathurin