2010-12-20 29 views
0

我的主题可能没有正确措辞。如何在变量中引用变量? (powershell)

我正在处理一些脚本并使用“Send-MailMessage”命令。我需要在消息正文中包含一些变量....我该如何做到这一点?这些变量是脚本中的目录,日志文件位置,IP地址等。当脚本完成或失败,我需要与有关作业相关信息发送一封电子邮件..

$ BOD =“这是在$ logfilelocation消息请参阅日志文件”

发送- - 要MAILMESSAGE用户@ user.com -Subject subject -From [email protected] -body $ bod -SmtpServer server

回答

2

您已经有了正确的想法。你只需要使用变量来建立你的$ bod字符串。 'here'字符串可能工作得很好。例如:

[email protected]" 
directory: $directory 
log file location: $logfileLocation 
ip address: $ipAddress 
"@ 

或者你问如何将这些值变成变量?