2017-03-08 36 views
1

我是PowerShell的新手。我创建其中包含一些数据的变量,我再传给到电子邮件生成:PowerShell - 管道 - 硬编码程序vs变量

$strEmailFile = "C:\Testing\SomeTextFile.txt" 

cat $strEmailFile | E:\sendmail.exe -t 

我的问题是我不想硬编码的电子邮件生成软件的驱动器。所以,我想的代码是这样的:

$strEmailFile = "C:\Testing\SomeTextFile.txt" 

$Dir = "E:" 

cat $strEmailFile | $Dir + "\sendmail.exe" -t 

但我不断收到以下错误:

"Expressions are only allowed as the first element of a pipeline."

有我使用的管道,但没有硬办法码?

+0

当你有'Send-MailMessage'时,你不需要'sendmail.exe'与PowerShell。 –

回答

1

你应该看看Send-MailMessage,但你的尝试之间的区别是,第一个是表达式,第二个是一个字符串,你不能管道到一个字符串。

但是如果你使用的call operator &你可以管到的是:

cat $strEmailFile | & ($Dir + "\sendmail.exe") -t 

请注意,您需要括号先运行地连接了变量和字符串)的表达。