title: ForEach-Loop with multiple arrays
body: <p>I currently have 4 arrays with different names of Organizational unit from our Active Directory.</p>
  
  <p>So I do a big evaluation and in order not to create a separate ForEach loop for each array (because this are like 400 lines of code) I would like to put the whole thing into a single loop. </p>
  
  <p>However, I need to know when which array is run through so that I can change something for this array in certain places by IF query. </p>
  
  <p>thats because not all arrays can use the code in this way and for example the searchbase for the Active Directory query must be changed for each array.</p>
  
  <p>Here i created a example  and described my problem in the comments. (&lt;# #>)</p>
  
  <pre class="lang-bsh prettyprint-override"><code>
  
  
  $OU1="1-Users","2-Users","3-Users"
  $OU2="1-Computers","2-Computers","3-Computers"
  $OU3="1-ServiceAccounts","2-ServiceAccounts","3-ServiceAccounts"
  
  foreach ($ou in $OU1 &lt;#AND OU2,OU3#&gt; ){
  
  if($OU1,$OU2 &lt;#= active#&gt; ){
  
   &lt;# if this array is active - do this code #&gt;
   $SearchBase = "OU="+$ou+",OU=SUBOU,DC=intra,DC=lan"
  
  }
  
  if($OU3 &lt;#= active#&gt;){
  
   &lt;# if this array is active - do this code #&gt;
  $SearchBase = "OU="+$ou+",DC=intra,DC=lan"
  
  }
  
  
   &lt;# do this code for all #&gt;
  
  }
  
  </code></pre>
  
  <p>I hope you understand what I mean and can help me with my problem. Thank you.</p>