[英]How to get PowerShell to send email with file paths
我在以下腳本中嘗試獲取通過電子郵件發送給我的某些文件的路徑位置,但是在將變量傳遞給函數時遇到問題。 我收到電子郵件,但正文為空。
有人可以幫我嗎?
謝謝,
拉馬爾·托馬斯(Lamar Thomas)
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
您需要為函數的VirusLoc參數提供一個參數,例如:
sendMain -VirusLoc $VirusLoc
順便說一句,該變量只包含一個文件名。 是否有多個文件,您可能要更改此行:
$VirusLoc = $_.FullName
至
$VirusLoc += "`n" + $_.FullName
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.