使用Powershell和文件夹中的文件进行打印

Roy*_*ton 3 printing powershell

我有一个脚本,可以进行一些现场打印.它目前无法正常工作,因为下面针对发送到文件夹进行打印的各种文件类型运行,但问题是它一次只能打印1个文档.

Start-Process –FilePath “c:\tests\*.docx” –Verb Print
Run Code Online (Sandbox Code Playgroud)

我有想法这样做来解决它:

    get-ChildItem "C:\Tests\*.docx" | `

    foreach-object {

    start-process -verb Print

}
Run Code Online (Sandbox Code Playgroud)

这似乎不起作用.那么我试过这个:

get-childitem "C:\Tests\*.xlsx" | `

foreach-object {

Start-Process -Filepath "C:\Program Files\Microsoft Office\Office14\EXCEL.exe" –Verb Print }
Run Code Online (Sandbox Code Playgroud)

也没运气,

返回此错误:

Start-Process : This command cannot be run due to the error: No application is associated with the specified file for this operation.
Run Code Online (Sandbox Code Playgroud)

我想我可能不会在这里看到这个过程.有关如何通过PowerShell实现文件夹中每个文件打印的所有人的想法?

Windows 7 64位和$ PSVersion = 5.0

提前致谢

Kai*_*hao 7

你非常接近,start-process需要文件的完整路径和名称

Get-ChildItem "c:\tests\*.docx" | ForEach-Object {start-process $_.FullName –Verb Print}
Run Code Online (Sandbox Code Playgroud)

使用foreach循环也应该对你有帮助

$files = Get-ChildItem “c:\tests\*.docx”

foreach ($file in $files){
    start-process -FilePath $file.fullName -Verb Print
}
Run Code Online (Sandbox Code Playgroud)