title: How do I check if a Resource Group already exists in Azure?
body: <p>I'm trying to improve my logic and make the code more efficient!  Currently I'm checking to see whether a Resource Group exists - if it does, random numbers are appended to the $resGroup variable.   I think it would more logical if I checked to see if the $resGroup + $num is checked for existence..  Any advice would be appreciated.</p>
  
  <pre><code>#LOGIN TO AZURE - DISPLAYS LOGIN DIALOG
  Login-AzureRmAccount
  
  #RESOURCEGROUP
  $resGroup = "group"
  
  #WEB APP 1
  $WebAppName1 = "FirstApp" + $resGroup
  $WebAppLocation1 = "Southeast Asia"
  
  #WEB APP 2
  $WebAppName2 = "SecondApp" + $resGroup
  $WebAppLocation2 = "southcentralus"
  
  $resGrpChk = Get-AzureRmResourceGroup -ResourceGroupName $resGroup -ev notPresent -ea 0
  
  
  if (!$resGrpChk)
  {  
  #CREATES A NEW RESOURCE GROUP
  New-AzureRmResourceGroup -Name $resGroup -Location "West Europe"    
  Write-Host 'RESOURCE GROUP CREATED' -fore white -back green
     }
   else
   {
     $num = Get-Random -Maximum 999
     $newGroup = "group"
     $resGroup = $group + $num
     New-AzureRmResourceGroup -Name $resGroup -Location "West Europe"  
   }
  </code></pre>