使用Powershell和MAPI在Outlook子文件夹中自动打印附件

时间:2016-03-24 12:43:19

标签: powershell outlook

我试图找到一种打印附件的方法,这些附件位于outlook的子文件夹中。我有一个脚本,它将它们提取到一个文件夹,但我想知道我是否应该从该文件夹中打印shell打印,或者是否只有一种打印方式,因为它们首先被发送到该文件夹​​。

    #file path
$filepath = “c:\tests\”


#set outlook to open
$o = New-Object -comobject outlook.application
$n = $o.GetNamespace(“MAPI”)


#you'll get a popup in outlook at this point where you pick the folder you want to scan
#$f = $n.pickfolder()
$Account = $n.Folders | ? { $_.Name -eq 'mymailaccount@company.com' };
$Inbox = $Account.Folders | ? { $_.Name -match 'Inbox' };
$f = $Inbox.Folders | ? { $_.Name -match 'colour' };

#now loop through them and grab the attachments
$f.Items | foreach {
    $_.attachments | foreach {
    Write-Host $_.filename
    $a = $_.filename
    $_.saveasfile((Join-Path $filepath $a)) | Foreach-Object { Start-Process -FilePath $_.FullName –Verb Print }
  }
} 

这会提取附件但不会打印。

这会打印该文件夹:

Dir c:\tests\*.* | Foreach-Object { Start-Process -FilePath $_.FullName –Verb Print }

我有这两个脚本,但我不确定如何从脚本1打印每个附件或组合脚本1和2,任何人都可以帮忙吗?

提前致谢

1 个答案:

答案 0 :(得分:0)

SaveAsFile没有返回文件名,所以你应该能够在打印后再有一个语句。

$_.saveasfile((Join-Path $filepath $a)) 
Start-Process -FilePath (Join-Path $filepath $a) –Verb Print }