管道文件到out-printer - powershell

时间:2016-03-29 13:41:04

标签: powershell printing

让这个脚本运行。几乎完成了我打印附件的任务,这些附件落在了outlook的特定子文件夹中

    $OutputFolder = 'C:\tests';

$outlook = New-Object -ComObject Outlook.Application; 
$olFolderInbox = 6;
$ns = $outlook.GetNameSpace("MAPI"); 
$inbox = $ns.GetDefaultFolder($olFolderInbox);
$inbox.Folders `
    | ? Name -eq 'colour' `
    | % Items `
    | % Attachments `
    | % {
        $OutputFileName = Join-Path -Path $OutputFolder -ChildPath $_.FileName;
        if (Test-Path $OutputFileName) {
            $FileDirectoryName = [System.IO.Path]::GetDirectoryName($OutputFileName);
            $FileNameWithoutExtension = [System.IO.Path]::GetFileNameWithoutExtension($OutputFileName);
            $FileExtension = [System.IO.Path]::GetExtension($OutputFileName);

            for ($i = 2; Test-Path $OutputFileName; $i++) {
                $OutputFileName = "{0} ({1}){2}" -f (Join-Path -Path $FileDirectoryName -ChildPath $FileNameWithoutExtension), $i, $FileExtension;
            }
        }
        Write-Host $OutputFileName;
        $_.SaveAsFile($OutputFileName)
    }

Remove-Item -Path C:\tests\*.jpg

Dir C:\tests\ | Out-Printer -name xerox-b8
Remove-Item -Path C:\tests\*.*

当我尝试管道打印对象时,我正在打印XML,或者只是目录内容

我试过了:

select-object (wrong)
get-childitem (wrong)
DIR C:\tests\*.* (only returns directory listing printout)

这些要么返回一堆XML垃圾,要么只返回一个目录列表,

如何使用PowerShell将文件夹的内容传送到打印机,当然可以这样做

0 个答案:

没有答案