title: $VM variable from whole subscription not resource group variable
body: <p>I've been trying to specify and target machines within a resource group which is a vaiable.</p>
  
  <p>The code I have is </p>
  
  <pre><code>[CmdletBinding()]
  Param(
    [Parameter(Mandatory=$True)]
     [string]$RG
  
  )
  Get-AzureRmResourceGroup | Where-Object {$_.ResourceGroupName -like "*$rg*"} 
  foreach ($rg in $rgs) 
  {
  $vms = Get-AzureRmVm -ResourceGroupName $_.ResourceGroupName
      $vms.ForEach({
          $tags = $_.Tags
          $tags['ShutdownSchedule_AllowStop'] = "whatever";
          Set-AzureRmResource -ResourceId $_.Id -Tag $tags -Force 
    })
  }
  </code></pre>
  
  <p>When I run this I get the following</p>
  
  <pre><code>The variable '$_' cannot be retrieved because it has not been set.
  At line:1 char:41
  + $vms = Get-AzureRmVm -ResourceGroupName $_.ResourceGroupName
  </code></pre>
  
  <p>However when I hardcode a name for $RG it seems to work. </p>
  
  <p>Confused.. </p>
  
  <p>Any pointers please?</p>
  
  <p>Thanks :)</p>