使用 PowerShell 比较两个文件

使用 PowerShell 比较两个文件

我是 PowerShell 新手,正在尝试使用 PowerShell 比较两个文件。还发送电子邮件通知。代码如下。

$from = "D:\\Program Files\\ibm\\cognos\\tm1_64\\cmplst.txt" 
$to = "C:\\compare"  
Copy-Item $from $to -Recurse -Force
$From = "[email protected]"
$To = "[email protected]"
$Cc = "xxxx@gmail@gmail"
$Subject = "String Comparison"
$Body = (Compare-Object (Get-Content C:\\compare\\cmplst-1.txt) (Get-Content C:\\compare\\cmplst.txt) -includeequal).InputObject
foreach($line in $comparison)
{
  $Body+= $line
}
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body $Body -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential [email protected]\xxx(password og gmail)
EOH

谁能告诉我错误是什么以及出现以下错误...

 "Cannot convert 'System.Object[]'
to the
    type 'System.String' required by parameter 'Body'. Specified method is not supported"

答案1

Send-MailMessage -From $From -to $To -Cc $Cc -Subject $Subject -Body ($Body|out-string) -SmtpServer $SMTPServer -port $SMTPPort -UseSsl -Credential [email protected]\xxx(password og gmail)

这将把主体格式化为Send-MailMessage命令的字符串

编辑:您最终可能会发现您得到的是对象类型而不是文本。

相关内容