我有两个琴弦。如果字符串相等,则无需执行任何操作,否则将触发else语句。 只是它适用于单行格式。但是,如果字符串像下面这样多行,则它不起作用。我在哪里做错了?
例如$myvar
:
log.txt
:
15732: 19/Jan/2019 15:40:06.969 ERROR message -outofmemory
log_2.txt
:
15732: 19/Jan/2019 15:40:06.969 ERROR message -fatal error 01 (122)
这是我的剧本:
$myvar
if (!($myvar)) {
Write-Host "No exception info to report" -BackgroundColor Green
} else {
$InputString = $myvar
$StringToMatch = Get-Content C:\ftp_file\report\dump.txt
if ($InputString -eq $StringToMatch) {
Write-Host "it will not be sent mail because same error message $($InputString)" -BackgroundColor Green
} else {
Write-Host "it will be sent mail" -BackgroundColor Cyan
Send-Mail blah blah..
#Export myvar variable again
"$myvar" | Out-File -FilePath C:\ftp_file\report\dump.txt
}
}