使用正则表达式的有效电子邮件

时间:2016-01-08 22:44:03

标签: regex validation powershell

我是PowerShell的新手,我遇到了一个解析CSV文档的脚本,以确定电子邮件是否格式正确。我的脚本确实执行,但不是使用无效的电子邮件过滤记录,而是导出包含所选列的所有记录。

请建议我缺少的东西。

$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

0 个答案:

没有答案