Email 在字符串输出之后,将if-else语句的结果输出到$subject和$body
嗨,我正在尝试输出if/else语句的结果,该语句会将另一个文本文件的结果输出到主题行和电子邮件正文中。我可以将其输出到powershell窗口,但我不知道如何将其放在主题行和电子邮件正文中。我对powershell还是很陌生,所以任何帮助都会很棒 谢谢 -尼克-Email 在字符串输出之后,将if-else语句的结果输出到$subject和$body,email,powershell,smtp,if-statement,Email,Powershell,Smtp,If Statement,嗨,我正在尝试输出if/else语句的结果,该语句会将另一个文本文件的结果输出到主题行和电子邮件正文中。我可以将其输出到powershell窗口,但我不知道如何将其放在主题行和电子邮件正文中。我对powershell还是很陌生,所以任何帮助都会很棒 谢谢 -尼克- # Check if the migrater is running $processToCheck = "calc" $process = Get-Process $processToCheck If (!($process))
# Check if the migrater is running
$processToCheck = "calc"
$process = Get-Process $processToCheck
If (!($process))
# Check what step in the process its in
{
$Service = get-content c:\AmicasToolService.properties | select-string "#AmicasService.processes=ArchiveRetrievalTool"
If ($Service) {"is done migrating"}
Else {"is done retrieving"}
# Send Email With Results
$From = "Olorin Migration Status <olorinmigration@gmail.com>"
$To = "nwarner@rchsd.org"
$SMTPServer = "smtp.gmail.com"
$SMTPPort = "587"
$Username = "email@gmail.com"
$Password = "password"
$subject = "Tape"+" "+(select-string "000..." c:\amicas2\config\ArchiveMigration.properties | select -Expand Matches | Select -Expand Value) + ($step)
$body = "Tape"+" "+(select-string "000..." c:\amicas2\config\ArchiveMigration.properties | select -Expand Matches | Select -Expand Value) + " " + "has finished retrieval or migration to Centera. Please check the log in the COA PACS folder for information on which step it is on in the process. \\naspfs01\Depts\ISD\COA\PACS\PACS_Library.xlsx"
$smtp = New-Object System.Net.Mail.SmtpClient($SMTPServer, $SMTPPort);
$smtp.EnableSSL = $true
$smtp.Credentials = New-Object System.Net.NetworkCredential($Username, $Password);
$smtp.Send($From, $To, $subject, $body);
}
我想你想要这个:
$msg = "$Service is done "
if ($Service) {
$msg += "migrating"
}
else {
$msg += "retrieving"
}
$subject = ... " $msg " ...
我多么希望PowerShell有一个三元运算符,例如:
$msg += $service ? "migrating" : "retrieving"
如果你同意,就投票表决