我有以下脚本,我正在尝试通过电子邮件将某些文件的路径位置发送给我,但我在将变量传递给函数时遇到问题。我收到了电子邮件,但身体是空的。
有人可以帮助我吗?
谢谢,
拉马尔·托马斯function sendMail($VirusLoc){
Write-Host "Sending Email"
#SMTP server name
$smtpServer = "mailhost.maxor.com"
#Creating a Mail object
$msg = new-object Net.Mail.MailMessage
#Creating SMTP server object
$smtp = new-object Net.Mail.SmtpClient($smtpServer)
#Email structure
$msg.From = "me@xxxxxx.com"
$msg.ReplyTo = "me@xxxxx.com"
$msg.To.Add("me@xxxxx.com")
$msg.subject = "CryptoLocker Virus Found On pcname"
$msg.body = $VirusLoc
#Sending email
$smtp.Send($msg)
}
Clear-Host
$arg = ("\\mxfsa01\Supsys\Red River Wholesale-old")
Set-Location $arg
$Files = Get-ChildItem -Recurse |Where-Object {$_.name -Like "Decrypt_Instruction.txt"} | % {
# Write-Host $_.FullName
$VirusLoc = $_.FullName
Write-Host $VirusLoc
}
sendMail
答案 0 :(得分:0)
您需要为函数的VirusLoc参数提供一个参数,例如:
sendMain -VirusLoc $VirusLoc
BTW该变量只保存一个文件名。是否有多个文件可能需要更改此行:
$VirusLoc = $_.FullName
到
$VirusLoc += "`n" + $_.FullName