How to open an Outlook contact using a Windows command-line script?

4

1

I tend to store a lot of information in the Notes fields of Outlook contacts.

Accessing this detailed info for a specific contact in Outlook 2013 requires many steps on the Windows desktop:

  • opening Outlook
  • switching to Contacts view
  • searching for the contact by name
  • opening the contact's unified "People view"
  • opening the full Outlook Contact card

As a power-user, I'd like to instead use some script:

Win-R oc John Smith

where Win-R is the shortcut to open a Run... window, and oc would be some type of script (PowerShell, VBA, Perl, ?) to directly open the detailed Outlook contact card for the given name.

Would there be any way to achieve this? Specific code would be great.

(Please note that unfortunately Outlook 2013 no longer makes its content accessible to Windows Search.)

Thanks.

Hugues

Posted 2013-05-28T14:42:07.210

Reputation: 1 067

Answers

2

Powershell example to get you started:

$outlook = new-object -com Outlook.Application
$contactFolder = $outlook.session.GetDefaultFolder(10)
$contacts = $contacts.Items
$firstContact = $contacts.GetFirst()
$contact.FirstName
$contact.Email1Address

It creates a COM connection to Outlook (must be installed),
then looks up the Contacts folder (#10),
then gets all the contact Items from the folder,
then Gets the first Contact item
and finally displays that contact's First Name and primary Email Address.

More info:

Ƭᴇcʜιᴇ007

Posted 2013-05-28T14:42:07.210

Reputation: 103 763

I second this method. Powershell is king. – MDT Guy – 2013-05-28T19:30:07.287

Thanks for the good pointers. I was hoping to be able to open the window with the Outlook Contact (to allow copying, editing, etc). Can you think of any way to do this programmatically? – Hugues – 2013-05-29T02:26:44.690

Thanks for the example! I was looking for a way to update my local address book entries via Powershell and this got me started. It helps that there's a $contact.Save() method, too. Thanks! – qJake – 2013-09-23T14:31:13.167

0

STTR

Posted 2013-05-28T14:42:07.210

Reputation: 6 180

Thanks for the suggestion -- I was using something like this previously with Outlook 2010. However, Outlook 2013 does not register its content in the Windows Search index. See http://www.google.com/search?q=outlook+2013+windows+search .

– Hugues – 2013-05-29T02:20:26.650

0

After much experimentation, I found a solution using the following Perl script:

#!/usr/bin/perl

use strict;
use warnings;

use Win32::OLE qw(in with);
$Win32::OLE::Warn = 2;
use Win32::OLE::Variant;  # to get Date scalar

my $olFolderContacts = 10;  # = olFolderContacts

my $outlook;
eval {
  $outlook = Win32::OLE->GetActiveObject('Outlook.Application');
};
die "$@\n" if $@;
if (!defined $outlook) {
  $outlook = Win32::OLE->new('Outlook.Application')
    or die "Oops, cannot start Outlook: ", Win32::OLE->LastError, "\n";
}

my $mapi = $outlook->GetNamespace('MAPI');  # see class NameSpace

my $searchname = "@ARGV";
my $contacts = $mapi->GetDefaultFolder($olFolderContacts); # (FolderType As OlDefaultFolders) As Folder
#  also olFolderCalendar, olFolderDeletedItems, olFolderDrafts, olFolderInbox, olFolderSuggestedContacts, ...
my @found;
for my $contact (in $contacts->{Items}) {
  my $name = $contact->{"FullName"};
  if ($name =~ /\b${searchname}\b/i) { push(@found, $contact); }
}
if (!@found) { die "Contact '$searchname' not found\n"; }
if (@found>1) {
  warn "Found multiple contacts matching '$searchname':\n";
  for (@found) { my $name = $_->{"FullName"}; warn "$name\n"; }
  exit 1;
}
my $contact = $found[0];
my $name = $contact->{"FullName"};
warn "Found '$name'\n";
$contact->Display;

Hugues

Posted 2013-05-28T14:42:07.210

Reputation: 1 067