仅在$ Pattern匹配时如何发送电子邮件

时间:2019-04-04 13:15:57

标签: powershell-v4.0

我有一个Powershell脚本,仅当$ Pattern是一个匹配项时才想发送电子邮件,如果nt不起作用。但是,无论是否匹配,它都会发送电子邮件。任何帮助将不胜感激

我尝试了-eq或-ne,但似乎都不起作用

$File = "C:\Data\PS\FTPUpload.log"
$Date = Get-Date -Format "MM/dd/yy"
$Text = "No Recount Data file found"
$Pattern = $date -match $Text
$MsgParam = @{
    To = "user <user@company.com>" 
    From = "script <no-reply-PLFTP@company.com>" 
    Subject = "Check CopiTrak Export Process" 
    Body = "No Recount Data file found"
    Attachment = "C:\Data\PS\FTPUpload.log"
    smtpServer = "1.2.3.4"
}
Get-Content $File | Select-string -Pattern $Pattern 
if($Pattern -eq False) {
##DoNothing
}
else
{
Send-MailMessage @MsgParam
}

0 个答案:

没有答案