title: Why are my values repeating when information is being inserted?
body: <p>I'm creating a script that goes through the Active directory and then searches for information based on another query when the information is entered and there is no information from the active directory the information from the last entered area enters into that SQL row even if there is no information for that site. Should I create an if else statement within one of the foreach loop to fix this problem?</p>
  
  <pre><code>while($rows.Read()){
      $SITEINFO = $rows['ActiveDirectoryOU']
  
          $ADARRAY= Get-ADGroupMember -Identity $SITEINFO | Get-ADUser -Properties ('Mail') 
  
      ForEach($OBJECT in $ADARRAY){ 
  
          $NAME = $OBJECT.Name 
          $USER = $OBJECT.SamAccountName
          $EMAIL = $OBJECT.Mail
          $SITECODE = $SITEINFO
  
          $INSERT = "INSERT INTO $TABLE VALUES ('$USER','$SITECODE','$EMAIL', '$NAME');"
              $SQL = $SQLCON.CreateCommand() 
              $SQL.CommandText = $INSERT    
              $SQL.ExecuteNonQuery()
          } 
        }
      }
  
  $SQLCONN.Close()
  </code></pre>