title: Valid email address using regular expression
body: <p>I am new to PowerShell and I am stuck with a script to parse CSV document to identify if the emails are in proper format or not. My script does execute but instead of filtering records with invalid email it exports all records with the selected columns.</p>
  
  <p>Please suggest as what I am missing.</p>
  
  <pre><code>$sourceFile = "d:\rvcc.csv"
  $targetFile = "d:\LMI-Invalid_Users_{0:yyyyMMMdd-HHmm}.csv" -f (Get-Date)
  
  $validemailDomain1 = "^[a-z]+\.[a-z]+@stu.raritanval.edu$"
  $validemailDomain2 = "^[a-z]+@stu.raritanval.edu$"
  $validemailDomain3 = "^[a-z0-9]+@stu.raritanval.edu$"
  $blankemail=""
  
  Import-CSV $sourceFile | % {
      # The big blue bar:  Or Verbose text: Write-Verbose "Checking:         $($_.EmailAddress)"
      Write-Progress -Activity "Checking user" -Status $_.EmailAddress
      If ($_.EmailAddress -NotMatch $validemailDomain1 -or 
              $_.EmailAddress -NotMatch $validemailDomain2 -or
              $_.EmailAddress -NotMatch $validemailDomain3 -or    
              $_.EmailAddress -NotMatch $blankemail) {
          $_ | Select-Object EmailAddress, FirstName, LastName, UserType, School_Id
      }
  } | Export-CSV $targetFile -NoTypeInformation
  </code></pre>