Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/email/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Email 在字符串输出之后,将if-else语句的结果输出到$subject和$body_Email_Powershell_Smtp_If Statement - Fatal编程技术网

Email 在字符串输出之后,将if-else语句的结果输出到$subject和$body

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))

嗨,我正在尝试输出if/else语句的结果,该语句会将另一个文本文件的结果输出到主题行和电子邮件正文中。我可以将其输出到powershell窗口,但我不知道如何将其放在主题行和电子邮件正文中。我对powershell还是很陌生,所以任何帮助都会很棒

谢谢

-尼克-

# 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"
如果你同意,就投票表决