使用 Read-Host 输入多行 [英] Use Read-Host to enter multiple lines
本文介绍了使用 Read-Host 输入多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用 Read-Host
cmdlet 来捕获多行?
Is there a way to use the Read-Host
cmdlet to capture multiple lines?
我目前的方法有点笨拙(实际上并不奏效):
My current approach is a bit awkward (and doesn't really work):
PS> Send-MailMessage -SmtpServer 'smtp.domain.xxx' -From 'First Last <flast@domain.xxx>' -To 'First Last <first.last@company.com>' -Subject 'Testing' -Body (Read-Host 'Enter text')
Enter text: line one `n line two `n line three
生成的电子邮件正文不是三行:
Resulting email body isn't three lines:
第一行`n第二行`n第三行
推荐答案
在你刚刚拥有的地方尝试这样的事情(读取主机)
Try something like this where you just have (Read-Host)
(@(While($l=(Read-Host).Trim()){$l}) -join("`n"))
您仅使用空白/空白行退出循环.
You exit the loop with a blank/white-space only line.
您可以使用 $_
而不是真正的变量,但我发现它令人毛骨悚然",所以我不这样做.
You can use $_
rather than a real variable but I find that "creepy" so I don't do it.
这篇关于使用 Read-Host 输入多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文