powershell - 从 (Send-MailMessage) 返回到 -body 参数中的语言特定变量
问题描述
我已经定义了几个具有不同正文内容的变量,稍后我可以在 Send-MailMessage 命令中使用 -Body 参数引用这些变量。
$bodyit = @"
Hello Italy
"@
$bodyde = @"
Hello Germany
"@
$bodymx = @"
Hello Mexico
"@
$bodye = @"
Hello International
"@
if ($var -eq "IT"){
return $bodyit
}elseif ($var -eq "DE"){
return $bodyde
}elseif ($var -eq "MX"){
return $bodymx
}else {return $bodye}
Send-MailMessage -from "..." -to "..." -subject "..." -smtp "..." -Body $return to specific $body
如何在 Send-MailMessage 中获得正确的返回类型?提前谢谢了。
解决方案
尝试使用开关而不是多个 if,还将您实际想要的值存储到$body
并$body
用于Send-Mail
正确响应。
试试这样:
switch ($var)
{
IT {
$body = @"
Hello Italy
"@
}
DE {
$body = @"
Hello Germany
"@
}
MX {
$body = @"
Hello Mexico
"@
}
default {
$body = @"
Hello International
"@
}
}
Send-MailMessage -from "..." -to "..." -subject "..." -smtp "..." -Body $body
推荐阅读
- javascript - Google 的二维码生成 api 不起作用
- angular - 图像 ALT 显示在源代码中但未显示在浏览器元素检查器中
- couchbase - 查询中未使用 Couchbase 数组索引
- java - 在没有xml配置的地图/列表中使用spring注入大量bean实例
- json - TypeScript 从 API 获取数据
- javascript - :hover 上的第二个动画在 mouseout 时重置第一个动画
- android - 迁移到新的 Places SDK 客户端会产生错误
- c++ - 用于存储航班的 LinkedQueue 实现
- typescript - React-Native:createRefCannot 添加属性值,对象不可扩展
- git - 无法在 Jenkins 中克隆 Git 项目