将Powershell Out-Printer用于文件时控制输出位置

时间:2015-03-04 18:24:11

标签: powershell printing

我有一个Powershell脚本,可以从服务器上的文件夹中检索所有图像文件(.jpg,.png),然后打印"它们是一个文件,特别是一个使用特定打印驱动程序的.prn文件。所有这一切都很好。问题是,我无法解决如何控制"打印"去,即它放置生成的.prn文件的位置。他们总是去我电脑上的Pictures文件夹。我希望将它们放入输入图像来自的同一服务器文件夹中。在上周,我已经搜索了Powershell out-print,out-file等的所有组合,我可以考虑尝试但到目前为止找不到解决方案。任何帮助,将不胜感激。这是我目前的剧本。

       $VerbosePreference = "Continue"
       add-type -AssemblyName microsoft.VisualBasic
       add-type -AssemblyName System.Windows.Forms
       $newext = ".prn"
       $Directory = "\\192.168.30.46\resource\Item\"
       $files = Get-ChildItem -Path $Directory –File
       $focus = 2000
       for ($i=0; $i -lt 5; $i++) {
       $newfile = $files[$i].BaseName + $newext     
           Start-Process $files[$i].FullName -verb Print | out-printer -name "Page Segment Print File"  
           start-sleep -Milliseconds $focus
           [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 250
           [System.Windows.Forms.SendKeys]::SendWait($newfile)
           start-sleep -Milliseconds 250
           [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
           start-sleep -Milliseconds 1500
           $focus = 250
       }
       Write-Verbose "Print Files Generated"

1 个答案:

答案 0 :(得分:0)

创建定义的根位置并连接,以便完全定义输出位置。

$VerbosePreference = "Continue"
   add-type -AssemblyName microsoft.VisualBasic
   add-type -AssemblyName System.Windows.Forms
   $rootdir = "C:\Temp\"
   $newext = ".prn"
   $Directory = "\\192.168.30.46\resource\Item\"
   $files = Get-ChildItem -Path $Directory –File
   $focus = 2000

   for ($i=0; $i -lt 5; $i++) {
   $newfile = $files[$i].BaseName + $newext     
       Start-Process $files[$i].FullName -verb Print | out-printer -name "Page Segment Print File"  
       start-sleep -Milliseconds $focus
   [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
   start-sleep -Milliseconds 250
   [System.Windows.Forms.SendKeys]::SendWait($(Join-Path $rootdir $newfile))
   start-sleep -Milliseconds 250
   [System.Windows.Forms.SendKeys]::SendWait("{ENTER}")
   start-sleep -Milliseconds 1500
   $focus = 250
}
Write-Verbose "Print Files Generated"`