使用powershell自动打印html文件

使用powershell自动打印html文件,html,powershell,printing,Html,Powershell,Printing,我想使用powershell将html文件打印到默认打印机。假设我有一个文件c:\test.html,其中包含以下文本: <html> <p> hello <b>world</b></p> <html> 你好,世界 如何将test.html打印到默认打印机 先谢谢你 get-content c:\test.html | out-printer 打印到默认打印机 编辑: 如果需要打印呈现的htlm页面: $ie =

我想使用powershell将html文件打印到默认打印机。假设我有一个文件c:\test.html,其中包含以下文本:

<html>
<p> hello <b>world</b></p>
<html>

你好,世界

如何将test.html打印到默认打印机

先谢谢你

get-content c:\test.html  | out-printer
打印到默认打印机

编辑:

如果需要打印呈现的htlm页面:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("c:\test.html")
$ie.ExecWB(6,2)
评论后编辑:

我可以在testprint.ps1文件中运行此命令:

$ie = new-object -com "InternetExplorer.Application"
$ie.Navigate("c:\test.html")
while ( $ie.busy ) { Start-Sleep -second 3 }
$ie.ExecWB(6,2)
while ( $ie.busy ) { Start-Sleep -second 3 }
$ie.quit()

我假设您对打印呈现的输出而不是html源代码感兴趣。谢谢!几乎完美。我看到我一直在运行IE,我应该运行“关闭”命令吗?我试过$ie.Quit()和$ie.Close(),但没有成功。有什么想法吗?要使IE会话以$IE的形式打开,您必须调用$IE.quit()。这不会关闭其他已打开的IE会话。你能再次尝试关闭所有其他IE会话吗?如果我退出,它不会打印。尝试了以下方法:“While($ie.Busy){Start Sleep-millides 400}$ie.Quit()”但它不打印。执行了5秒睡眠的harcode,它就工作了。需要在主线程中进行等待或类似的操作。很高兴它有帮助!请参见msdn上的OLECMDID、OLECMDEXECOPT,它们是ExecWB成员的值!