Friday, July 17, 2009

Save Outlook attachements to disk

This handy bit of Powerscript code allows you to save attachements in your Outlook inbox to disk:

You need to pass a file name, not just a destination directory to SaveAsFile.The attachment has a FileName property.
This code groups attachments with same name and saves the first attachment in each group, if the attachment is corrupt or if it can't save it the Trap handles the exception; in this sample it just writes a message.You could also iterate through each group's attachments and append a different number to the name in order to save all.

$inbox=6
$outlook = new-object -com Outlook.Application
$inbox = $outlook.Session.GetDefaultFolder($inbox)
foreach ($group in $inbox.items % {$_.attachments} group filename) {
trap {
Write-Host There was a problem saving $fName
continue}
if ($group.Name.startswith("SECTSPDR")) {
$fName = "C:\TEMP\$($group.Name)"
$group.Group[0].saveasfile($fName)
if ($?) {Write-Host $fName was saved succesfuly.}
}
}

Backup options on your home network

I think I have settled on a good backup option for my desktop at home. I have an external hard drive connected to my desktop. Previously, I had installed rsync via cygwin which I have successfully used in the past. However, every few days I would find the process hung and had to reboot the machine. It appeared that this was not a common problem and it's not very easy finding support for free tools like cygwin (understandably)

Recently I cam across a tool similar to rsync from Microsoft named robocopy. This utility is included in the Windows resource tookit. It seems to be working well and have not yet found it hung like rsync was doing.

I also added an email to the job to mail the results of the run. For this I installed blat. I also had to hook into an SMTP server (using Gmail for this). Since GMail required SSL I needed to install and configure stunnel to communicate via SSL.