使用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