printing the attachments on email in Outlook from a PowerShell script

  • Follow


I need help writing a PowerShell script to automate printing
the attachments to email in Outlook.

  - Larry
0
Reply Larry__Weiss 4/18/2010 10:42:17 PM

I frequent a few forums...  Did you (or someone else) already ask this 
question a few months ago?

You may have a problem automating the printing of the attachments, but you 
can definitely save them all to a common directory.  I'm not sure if you can 
select multiple documents of different formats and easily right-click to 
print them all.

Are the attachments all the same format/document type?

Marco

"Larry__Weiss" <lfw@airmail.net> wrote in message 
news:#Cc7mh03KHA.3352@TK2MSFTNGP02.phx.gbl...
> I need help writing a PowerShell script to automate printing
> the attachments to email in Outlook.
>
>  - Larry 

0
Reply Marco 4/19/2010 12:42:19 PM


I'm assisting a friend of mine with the creation of this script,
and I have discovered some previous threads, but nothing that ties
the whole thing together.

The attached file format will be PDF.  The email client is Outlook.

I want to use this as a real-world example of the use of PowerShell to 
demonstrate at the NTPCUG PowerShell SIG.

  - Larry


On 4/19/2010 7:42 AM, Marco Shaw [MVP] wrote:
> I frequent a few forums...  Did you (or someone else) already ask this
> question a few months ago?
>
> You may have a problem automating the printing of the attachments, but
> you can definitely save them all to a common directory. I'm not sure if
> you can select multiple documents of different formats and easily
> right-click to print them all.
>
> Are the attachments all the same format/document type?
>
> Marco
>
> "Larry__Weiss" <lfw@airmail.net> wrote in message
> news:#Cc7mh03KHA.3352@TK2MSFTNGP02.phx.gbl...
>> I need help writing a PowerShell script to automate printing
>> the attachments to email in Outlook.
>>
>> - Larry
>
0
Reply Larry__Weiss 4/19/2010 2:05:57 PM

Are you a bit familiar with the outlook object model? using it could bring 
the solution. Let me know. I could try to create a code snippet. Do you use 
Outlook as an Exchange-Client oder pop/imap-client?

Reinhard

"Larry__Weiss" wrote:

> I need help writing a PowerShell script to automate printing
> the attachments to email in Outlook.
> 
>   - Larry
> .
> 
0
Reply Utf 4/20/2010 11:33:01 AM

It is the pop based client.

  - Larry

On 4/20/2010 6:33 AM, rkd wrote:
> Are you a bit familiar with the outlook object model? using it could bring
> the solution. Let me know. I could try to create a code snippet. Do you use
> Outlook as an Exchange-Client oder pop/imap-client?
>
> Reinhard
>
> "Larry__Weiss" wrote:
>
>> I need help writing a PowerShell script to automate printing
>> the attachments to email in Outlook.
>>
>>    - Larry
>> .
>>
0
Reply Larry__Weiss 4/20/2010 1:51:04 PM

Hi Larry, please try this once:

This example assumes you have a subfolder 'Pdf' under your inbox folder 
where the e-mails with the pdf-attachments reside and you have a folder 
C:\pdf in your filesystem.
Outlookversion: 2002 (hope other/higher versions support this code too)

$ol = New-Object  -Com Outlook.Application
$ns = $ol.GetNameSpace('MAPI')
$olinbox = 6
$inbox = $ns.GetDefaultFolder( $olInbox )
$olPdfFolder = $inbox.Folders.Item('pdf')
$olPdfFolder.Items | %{ 
    foreach ($attachment in $_.Attachments)
    {
        $attachment.SaveAsFile( "C:\pdf\$($attachment.FileName)") 
     }
}

$shell = New -com Shell.Application
$shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }

hope this meets your needs and you get success.
Reinhard

PS: you can also transfer the code above in just 2 lines. the first one does 
the outlook job, the second one does the shell job. pretty cool what we can 
do with psh.
"Larry__Weiss" wrote:

> It is the pop based client.
> 
>   - Larry
> 
> On 4/20/2010 6:33 AM, rkd wrote:
> > Are you a bit familiar with the outlook object model? using it could bring
> > the solution. Let me know. I could try to create a code snippet. Do you use
> > Outlook as an Exchange-Client oder pop/imap-client?
> >
> > Reinhard
> >
> > "Larry__Weiss" wrote:
> >
> >> I need help writing a PowerShell script to automate printing
> >> the attachments to email in Outlook.
> >>
> >>    - Larry
> >> .
> >>
> .
> 
0
Reply Utf 4/21/2010 7:56:01 AM

Thanks!  I'll test it and give you some feedback.
Do you have a reference for the Outlook object model that you can recommend?

  - Larry

On 4/21/2010 2:56 AM, rkd wrote:
> Hi Larry, please try this once:
>
> This example assumes you have a subfolder 'Pdf' under your inbox folder
> where the e-mails with the pdf-attachments reside and you have a folder
> C:\pdf in your filesystem.
> Outlookversion: 2002 (hope other/higher versions support this code too)
>
> $ol = New-Object  -Com Outlook.Application
> $ns = $ol.GetNameSpace('MAPI')
> $olinbox = 6
> $inbox = $ns.GetDefaultFolder( $olInbox )
> $olPdfFolder = $inbox.Folders.Item('pdf')
> $olPdfFolder.Items | %{
>      foreach ($attachment in $_.Attachments)
>      {
>          $attachment.SaveAsFile( "C:\pdf\$($attachment.FileName)")
>       }
> }
>
> $shell = New -com Shell.Application
> $shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }
>
> hope this meets your needs and you get success.
> Reinhard
>
> PS: you can also transfer the code above in just 2 lines. the first one does
> the outlook job, the second one does the shell job. pretty cool what we can
> do with psh.
> "Larry__Weiss" wrote:
>
>> It is the pop based client.
>>
>>    - Larry
>>
>> On 4/20/2010 6:33 AM, rkd wrote:
>>> Are you a bit familiar with the outlook object model? using it could bring
>>> the solution. Let me know. I could try to create a code snippet. Do you use
>>> Outlook as an Exchange-Client oder pop/imap-client?
>>>
>>> Reinhard
>>>
>>> "Larry__Weiss" wrote:
>>>
>>>> I need help writing a PowerShell script to automate printing
>>>> the attachments to email in Outlook.
>>>>
>>>>     - Larry
>>>> .
>>>>
>> .
>>
0
Reply Larry__Weiss 4/21/2010 9:46:40 PM

> $shell = New -com Shell.Application
> $shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }

Very interesting approach!  My suggestions would have been to use COM with 
Microsoft Word to print the PDFs, but that would likely be more resource 
intensive.

Marco 

0
Reply Marco 4/21/2010 11:38:29 PM

I used the online help of my outlook installation, topic 'forms and 
programming informations'.
But it can be that the programming part of the online help is part of an 
optional installation topic, so a standard installation doesn't provide such 
a help topic
Reinhard

"Larry__Weiss" wrote:

> Thanks!  I'll test it and give you some feedback.
> Do you have a reference for the Outlook object model that you can recommend?
> 
>   - Larry
> 
> On 4/21/2010 2:56 AM, rkd wrote:
> > Hi Larry, please try this once:
> >
> > This example assumes you have a subfolder 'Pdf' under your inbox folder
> > where the e-mails with the pdf-attachments reside and you have a folder
> > C:\pdf in your filesystem.
> > Outlookversion: 2002 (hope other/higher versions support this code too)
> >
> > $ol = New-Object  -Com Outlook.Application
> > $ns = $ol.GetNameSpace('MAPI')
> > $olinbox = 6
> > $inbox = $ns.GetDefaultFolder( $olInbox )
> > $olPdfFolder = $inbox.Folders.Item('pdf')
> > $olPdfFolder.Items | %{
> >      foreach ($attachment in $_.Attachments)
> >      {
> >          $attachment.SaveAsFile( "C:\pdf\$($attachment.FileName)")
> >       }
> > }
> >
> > $shell = New -com Shell.Application
> > $shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }
> >
> > hope this meets your needs and you get success.
> > Reinhard
> >
> > PS: you can also transfer the code above in just 2 lines. the first one does
> > the outlook job, the second one does the shell job. pretty cool what we can
> > do with psh.
> > "Larry__Weiss" wrote:
> >
> >> It is the pop based client.
> >>
> >>    - Larry
> >>
> >> On 4/20/2010 6:33 AM, rkd wrote:
> >>> Are you a bit familiar with the outlook object model? using it could bring
> >>> the solution. Let me know. I could try to create a code snippet. Do you use
> >>> Outlook as an Exchange-Client oder pop/imap-client?
> >>>
> >>> Reinhard
> >>>
> >>> "Larry__Weiss" wrote:
> >>>
> >>>> I need help writing a PowerShell script to automate printing
> >>>> the attachments to email in Outlook.
> >>>>
> >>>>     - Larry
> >>>> .
> >>>>
> >> .
> >>
> .
> 
0
Reply Utf 4/22/2010 8:33:02 AM

Yes you're very right, Marco. the shell.application Com-object offers a few 
very interessting things. I neglected it for a long time. Only in the last 
time i took my focus more on it and it seems that it payed out :-)
Reinhard

"Marco Shaw [MVP]" wrote:

> > $shell = New -com Shell.Application
> > $shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }
> 
> Very interesting approach!  My suggestions would have been to use COM with 
> Microsoft Word to print the PDFs, but that would likely be more resource 
> intensive.
> 
> Marco 
> 
0
Reply Utf 4/22/2010 8:44:01 AM

Thanks again for the PowerShell code.

We used it as an example to demonstrate PowerShell usage at
the North Texas PC Users Group PowerShell SIG in Dallas
this morning.   The only thing we had to change was
the next to last line where we modified it to be

  $shell = New-Object -com Shell.Application

  - Larry


On 4/21/2010 2:56 AM, rkd wrote:
> Hi Larry, please try this once:
>
> This example assumes you have a subfolder 'Pdf' under your inbox folder
> where the e-mails with the pdf-attachments reside and you have a folder
> C:\pdf in your filesystem.
> Outlookversion: 2002 (hope other/higher versions support this code too)
>
> $ol = New-Object  -Com Outlook.Application
> $ns = $ol.GetNameSpace('MAPI')
> $olinbox = 6
> $inbox = $ns.GetDefaultFolder( $olInbox )
> $olPdfFolder = $inbox.Folders.Item('pdf')
> $olPdfFolder.Items | %{
>      foreach ($attachment in $_.Attachments)
>      {
>          $attachment.SaveAsFile( "C:\pdf\$($attachment.FileName)")
>       }
> }
>
> $shell = New -com Shell.Application
> $shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }
>
> hope this meets your needs and you get success.
> Reinhard
>
> PS: you can also transfer the code above in just 2 lines. the first one does
> the outlook job, the second one does the shell job. pretty cool what we can
> do with psh.
 >
> "Larry__Weiss" wrote:
>> It is the pop based client.
>>
>>
>> On 4/20/2010 6:33 AM, rkd wrote:
>>> Are you a bit familiar with the outlook object model? using it could bring
>>> the solution. Let me know. I could try to create a code snippet. Do you use
>>> Outlook as an Exchange-Client oder pop/imap-client?
>>>
>>> Reinhard
>>>
>>> "Larry__Weiss" wrote:
>>>> I need help writing a PowerShell script to automate printing
>>>> the attachments to email in Outlook.
>>>>
0
Reply Larry__Weiss 5/15/2010 10:36:02 PM

Now that I have a start on this script, I'd like to add more smarts to 
it (like moving the emails to another folder after saving the 
attachments so the next time I execute it, it won't re-print any 
previous attachments).

Is there a good book out there that explains the Outlook object model?
And if there is a revision of a book that shows PowerShell examples of 
using the Outlook object model that would be ideal.

  - Larry


On 5/15/2010 5:36 PM, Larry__Weiss wrote:
> Thanks again for the PowerShell code.
>
> We used it as an example to demonstrate PowerShell usage at
> the North Texas PC Users Group PowerShell SIG in Dallas
> this morning. The only thing we had to change was
> the next to last line where we modified it to be
>
> $shell = New-Object -com Shell.Application
>
> - Larry
>
>
> On 4/21/2010 2:56 AM, rkd wrote:
>> Hi Larry, please try this once:
>>
>> This example assumes you have a subfolder 'Pdf' under your inbox folder
>> where the e-mails with the pdf-attachments reside and you have a folder
>> C:\pdf in your filesystem.
>> Outlookversion: 2002 (hope other/higher versions support this code too)
>>
>> $ol = New-Object -Com Outlook.Application
>> $ns = $ol.GetNameSpace('MAPI')
>> $olinbox = 6
>> $inbox = $ns.GetDefaultFolder( $olInbox )
>> $olPdfFolder = $inbox.Folders.Item('pdf')
>> $olPdfFolder.Items | %{
>> foreach ($attachment in $_.Attachments)
>> {
>> $attachment.SaveAsFile( "C:\pdf\$($attachment.FileName)")
>> }
>> }
>>
>> $shell = New -com Shell.Application
>> $shell.Namespace('C:\pdf').Items() | %{ $_.InvokeVerb('Print') }
>>
>> hope this meets your needs and you get success.
>> Reinhard
>>
>> PS: you can also transfer the code above in just 2 lines. the first
>> one does
>> the outlook job, the second one does the shell job. pretty cool what
>> we can
>> do with psh.
>  >
>> "Larry__Weiss" wrote:
>>> It is the pop based client.
>>>
>>>
>>> On 4/20/2010 6:33 AM, rkd wrote:
>>>> Are you a bit familiar with the outlook object model? using it could
>>>> bring
>>>> the solution. Let me know. I could try to create a code snippet. Do
>>>> you use
>>>> Outlook as an Exchange-Client oder pop/imap-client?
>>>>
>>>> Reinhard
>>>>
>>>> "Larry__Weiss" wrote:
>>>>> I need help writing a PowerShell script to automate printing
>>>>> the attachments to email in Outlook.
>>>>>
0
Reply Larry__Weiss 5/26/2010 12:32:54 AM

11 Replies
1010 Views

(page loaded in 0.027 seconds)

Similiar Articles:































7/19/2012 6:07:42 PM


Reply: