powershell - 使用PowerShell 2.0 在客户端遍历目录打印文件?

标签 powershell webdav

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

最佳答案

下面的命令应该可以解决这个问题 - 遍历目录中的所有文件,获取它们的内容并将内容发送到当前打印机。我测试了它,它工作正常:

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

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

关于powershell - 使用PowerShell 2.0 在客户端遍历目录打印文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3757834/

相关文章:

sql-server-2008 - Powershell 无法识别 invoke-sqlcmd

powershell - 更改 powershell 中 [Environment]::GetEnvironmentVariables ('Machine' ) 命令的输出或获取环境变量名称列表

windows - EC2 Windows 用户数据 : Powershell does not run as expected

iphone - IOS 中的 WebDAV 支持

c# - 使用 WebDAV 和 C# 读取电子邮件的主题和正文

java - Exchange 2007 日历的 WebDAV 查询 : 400 Error

javascript - 我删除了 package.json 和 Gruntfile.js,现在 Grunt 将不会加载依赖项

Powershell 启动进程 : This command cannot be executed due to the error: Access is denied

http - WebDAV 属性即使在设置之后也会在请求中返回

powershell - 通过WebDAV编写脚本文件操作的推荐解决方案?