$SourcePath= "\\sharedfolder\aa" #Change it accordingly
$DestinationPath= "\\sharedfolder\bb" #Change it accordingly
$boolCompare= "true"
$TempComparisonFile = "C:\a.txt" #Change it accordingly
$TempCompareResultFile = "C:\result.txt" #Change it accordingly
if ($boolCompare -eq "true") {
if (Test-Path $TempComparisonFile){
Remove-Item $TempComparisonFile -force
echo removed TempComparisonFile
}
if (Test-Path $TempCompareResultFile){
Remove-Item $TempCompareResultFile -force
echo removed TempCompareResultFile
}
New-Item $TempComparisonFile -type file -force
$Contxt = "Load " + $SourcePath + " " + $DestinationPath
$Contxt | Out-File -Append $TempComparisonFile -Encoding ascii
$Contxt = "expand all"
$Contxt | Out-File -Append $TempComparisonFile -Encoding ascii
$Contxt = "select all"
$Contxt | Out-File -Append $TempComparisonFile -Encoding ascii
$Contxt = "compare binary"
$Contxt | Out-File -Append $TempComparisonFile -Encoding ascii
$Contxt = "folder-report layout:summary options:display-right-newer-orphans,column-none output-to:""$TempCompareResultFile"""
$Contxt | Out-File -Append $TempComparisonFile -Encoding ascii
$content = gc $TempComparisonFile
foreach($line in $content) {
Write-Host $line
}
$ExeCompare = '"' + "C:\Beyond Compare 3\BCompare.exe" +'"' #Change it accordingly
$Arg ='"@' + $TempComparisonFile + '"'
Start-Process -FilePath $ExeCompare -ArgumentList $Arg -Wait
###############################发送邮件部分开始####################
$EmailFrom = “xx@xx.com” #Change it accordingly
$EmailTo = “xx@xx.com” #Change it accordingly
$Subject = “Txt Comparison Result” #Change it accordingly
#$Body = "Any content" #Change it accordingly
$Body = $TempCompareResultFile,[System.IO.File]::ReadAllText($TempCompareResultFile) #Incase enter mark is not able to transfer in email
echo $Body
$SMTPServer = “smtp.xxxxxx.local” #Change it accordingly
$SMTPClient = New-Object Net.Mail.SmtpClient($SmtpServer, 25)
$SMTPClient.EnableSsl = $false #Necessary be set to false, but means not secured
#$SMTPClient.Credentials = New-Object System.Net.NetworkCredential(“Domain\XXX”, “XXX”); #Not necessary
$SMTPClient.Send($EmailFrom, $EmailTo, $Subject, $Body)
############################发送邮件部分结束########################
}
Powershell 发送邮件
于 2022-06-22 15:26:23 首次发布