2010-09-21 80 views
3

使用Powershell 2.0,是否可以遍历客户端安装的打印机上的目录和打印文件?使用PowerShell 2.0遍历目录并在客户端打印文件?

我得到了下面的PowerShell脚本。它在共享网络驱动器上工作良好,但我如何实际修改并使用它来查询WebDav文件夹的内容,然后在客户端(而不是服务器端)仅打印.PDF文件扩展名?

PowerShell脚本遍历目录:

function print-file($file) { 
    begin { 
     function internal-printfile($thefile) { 
      if ($thefile -is [string]) { 
       $filename = $thefile 
      } 
      else { 
       if ($thefile.FullName -is [string]) { 
        $filename = $THEfile.FullName 
       } 
      } 
      $start = new-object System.Diagnostics.ProcessStartInfo $filename 
      $start.Verb = "print" 
      [System.Diagnostics.Process]::Start($start) 
     } 

     if ($file -ne $null) { 
      $filespecified = $true; 
      internal-printfile $file 
     } 
    } 
    process { 
     if (!$filespecified) { 
      write-Host process ; internal-printfile $_ 
     } 
    } 
} 

dir *.pdf -r | print-file 

回答

3

下面的命令应该做的伎俩 - 遍历目录中的所有文件,得到他们的内容和发送内容到当前的打印机。我测试了它,它工作正常:

Get-ChildItem . -filter *.* -recurse | get-content | out-printer 

它从当前文件夹中获取所有文件。

+0

是的,它适用于已经映射到Windows资源管理器的普通目录。 – 2010-10-08 06:43:43

+0

感谢您的回复。 – 2010-10-08 06:43:58

+0

这里是我用来遍历目录的另一个脚本: – 2010-10-11 00:13:41