我正在尝试使用Powershell输出包含一些前/后内容的表格,然后通过电子邮件发送,但前/后内容在电子邮件中显示为"System.String []".其余的内容似乎很好,如果我将HTML字符串输出到控制台,一切看起来都很好.
function Send-SMTPmail($to, $from, $subject, $smtpserver, $body) {
$mailer = new-object Net.Mail.SMTPclient($smtpserver)
$msg = new-object Net.Mail.MailMessage($from,$to,$subject,$body)
$msg.IsBodyHTML = $true
$mailer.send($msg)
}
$Content = get-process | Select ProcessName,Id
$headerString = "<table><caption> Foo. </caption>"
$footerString = "</table>"
$MyReport = $Content | ConvertTo-Html -fragment -precontent $headerString -postcontent $footerString
send-SMTPmail "my Email" "from email" "My Report Title" "My SMTP SERVER" $MyReport
Run Code Online (Sandbox Code Playgroud)
在我的电子邮件中显示为:
System.String[]
ProcessName Id
... ...
System.String[]
Run Code Online (Sandbox Code Playgroud)
执行out-file然后调用invlable-item与发送电子邮件的结果相同...
在尝试在Powershell中运行外部程序时,我能够运行此特定行的唯一方法是使用[Diagnostics.Process]::Start().但是,这似乎不适用于旧版操作系统,如Windows XP.还有另一种选择吗?我尝试了一种&符号(&)类型的运行,但它让我的论点更加突出.这就是我所拥有的:
$vmrc = "C:\Program Files\Common Files\VMware\VMware Remote Console Plug-in\vmware-vmrc.exe"
$vmrcArgs = "-h $($server) -p $($unencoded) -M $($moref)"
[void] [Diagnostics.Process]::Start($vmrc, $vmrcArgs)
Run Code Online (Sandbox Code Playgroud)