2017-03-16 108 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