使用 Powershell 和文件夹中的文件进行打印 [英] Printing with Powershell and files in folders
问题描述
我有一个脚本可以进行一些现场打印.目前它不太好用,因为下面针对发送到文件夹进行打印的各种文件类型运行,但问题是它一次只能打印 1 个文档.
I have a script which does some onsite printing. It doesnt work too well at the moment as the below runs for various file types which are sent to a folder to print, but the problem is it will only print 1 document at a time.
Start-Process –FilePath "c:\tests\*.docx" –Verb Print
为了解决这个问题,我想到了这样做:
I had the idea of doing this to get around it:
get-ChildItem "C:\Tests\*.docx" | `
foreach-object {
start-process -verb Print
}
虽然这似乎不起作用.然后我尝试了这个:
This doesnt seem to work though. So then i tried this:
get-childitem "C:\Tests\*.xlsx" | `
foreach-object {
Start-Process -Filepath "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" –Verb Print }
也没有运气,
返回此错误:
Start-Process : This command cannot be run due to the error: No application is associated with the specified file for this operation.
我想我可能没有看到这里的过程.关于如何通过powershell实现文件夹中每个文件的打印的任何想法?
I think i am maybe not visualing the process here. Any ideas at all anyone on how to achieve printing of every file in a folder via powershell?
Windows 7 64 位和 $PSVersion = 5.0
Windows 7 64 bit and $PSVersion = 5.0
提前致谢
推荐答案
你很接近,start-process
需要文件的完整路径和名称:
You are very close, start-process
needs the full path and name of the file:
Get-ChildItem "c:\tests\*.docx" | ForEach-Object {start-process $_.FullName –Verb Print}
使用 foreach 循环也应该对您有所帮助:
Using a foreach loop should help you too:
$files = Get-ChildItem "c:\tests\*.docx"
foreach ($file in $files){
start-process -FilePath $file.fullName -Verb Print
}
这篇关于使用 Powershell 和文件夹中的文件进行打印的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!