title: Using Azure pipeline in yaml to loop through 2 variables simultaneously
body: <p>Requirement: To shutdown or start VM's in a specific resource group using powershell</p>
  <p>Variables: List of VM's are stored comma separated in a variable in a variable group which i use split(,) to read each of the during iterating through the loop.
  Resource group name also needs to be stored in a variable or can be stored as a parameter as well.</p>
  <p>My powershell script:</p>
  <pre><code> Param 
      (    
          [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] 
          $AzureVMList,
          [Parameter(Mandatory=$true)][ValidateNotNullOrEmpty()] 
          $Rgname
      ) 
       
          $AzureVMs = $AzureVMList.Split(&quot;,&quot;) 
          [System.Collections.ArrayList]$AzureVMsToHandle = $AzureVMs 
  
  
  
  foreach ( $AzureVM in $AzureVMsToHandle )
  {
      Stop-AzureRmVM -ResourceGroupName &quot;$Rgname&quot; -Name  &quot;$AzureVM&quot;
      
  }
  </code></pre>
  <p>My Azure pipeline outline</p>
  <pre><code>parameters:
  - name: Rgname
    type: object
    default:
    - rg1
    - rg2  
  - variables
      vmlist1: vm1,vm2,vm3
      vmlist2: vm4,vm5,vm6
  
  stages: 
    - stage: turnon
      displayName: 'Turn ON VM'
      jobs: 
        - job: 'TurnONVM'
          displayName: 'Turn on VM'
          pool:
            vmImage: 'vs2017-win2016'  
          steps:
          - ${{ each rgname in parameters.resourcegroup }}:
            - task: AzurePowerShell@5
              displayName: turn on myvm&quot;
              inputs:
                azureSubscription: 'MySubscription'
                ScriptType: 'FilePath'
                ScriptPath: '$(System.DefaultWorkingDirectory)/vm-pipelines/turn-on-vm.ps1'
                ScriptArguments: '-AzureVMList $(vmlist1) -Rgname ${{ parameters.rgname }}'
                azurePowerShellVersion: 'LatestVersion'
                errorActionPreference: silentlyContinue
  </code></pre>
  <p>This might work if i have only one resource group. I need to specify multiple resource groups and corresponding variable for storing the list of vm's. I have no idea how would i define pipeline in such a way that execute the script for RG1 with VMlist1 likewise, RG2 with VMlist2</p>