title: Foreach loop in a if statement
body: <p>Wrote a small script to check if certain AD groups exists. For some reason it wont loop through the given array. It only writes the first value of the array to the console. When I put a breakpoint on:</p>
  
  <pre><code>foreach ($item in $SecGroupNames)
  </code></pre>
  
  <p>I see $secGroupNames being filled with the gives values, can anyone help me out? Can't figure it out for this one.</p>
  
  <p>Code:</p>
  
  <pre><code>Import-Module activedirectory
  $SecGroupNames = @(  
                       "DB_DATAREADER",
                       "DB_DATAWRITER",
                       "DB_OWNER",
                       "SQL_Public",
                       "SQL_SA",
                       "SQL_SecurityAdmin"
                    )
  
      foreach ($item in $SecGroupNames)
        {   
          If (Get-ADGroup $item)
          {     
              Write-Host -ForegroundColor Yellow "$item Exists!"
              return $true; 
          }
          else
          {
              Write-Host -ForegroundColor Green "$Item Does not exist, Do something!" 
              return $false;
          }
        }
  </code></pre>
  
  <p>Output:</p>
  
  <pre><code>PS C:\Scripts\CreateOUgroups&gt; C:\Scripts\CreateOUgroups\FunctionCheckSecurityGroup.ps1
  DB_DATAREADER Exists!
  True
  </code></pre>