Outlook Tasks in PowerShell and Vim

Getting Outlook Tasks in PowerShell is actually pretty easy. All you need to do is use the Office Interop to get access to the default tasks folder, then iterate through the items that are returned.

Create a file called Get-OutlookTask.ps1 in your scripts folder, and paste the following code:

Add-Type -AssemblyName Microsoft.Office.Interop.Outlook
$folders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type]
$outlook = New-Object -ComObject outlook.application
$mapi = $outlook.GetNameSpace("mapi")
$tasks = $mapi.getDefaultFolder($folders::olFolderTasks)

foreach($task in $tasks.Items)

Naturally, you could customize this script to work any way you like – for example, you could sort by priorty or date, or you could show an extra column for category information. I have actually set up an alias to this script, so all I have to do is type tasks to see all my current tasks.

If you have set Vim to work with PowerShell, you can import your Outlook Tasks directly into the open document by using the Vim command:

:r! tasks

Pretty cool huh? If you’re looking to add Outlook Tasks in a similar way, you can check out this script by Lee Holmes. I use this one with the alias of nt to save on all that extra typing.

If you want to be able to add Outlook Tasks from Vim, I suggest you add the following function to your vimrc file:

function! Task(args)
  system("nt \\\"" . a:args . "\\\"")

command! -nargs=1 Task :call Task('')

Now you just need to call :Task buy milk and it’ll get added – without switching to the shell itself.

  1. Pingback: Setting up Vim to work with PowerShell | Julian Kay's Blog

  2. Pingback: Querying TFS with TFPT.EXE and PowerShell - Julian Kay's Blog

  3. Thanks for the tip! It got me going on scripting adding/setting CustomProperties for Tasks.

Leave a Comment...