Out-vCard: Exporting Outlook Address Book

Our local identity management guru Jackson Shaw tasked me with giving him an easy way to export contact information from corporate address book so you can then send it to someone for their reference. The standard format for Outlook to import contact information is vCard, but the problem is that Outlook can export to vCard only personal contacts, but not GAL entries. Needless to say, PowerShell is the answer. 😉

This is the command-line which solves the task:

Get-QADUser "Dmitry Sotnikov" | Out-vCard

This will locate a user in your AD whose name is "Dmitry Sotnikov" (which probably means you work for Quest) and create a file "Dmitry Sotnikov.vcf" at the c:\ drive root.

If you want to export all members of a DL – this will work too:

Get-QADGroupMember DL.ProjectA | Out-vCard

This will create a vCard for each DL member.

And because it only reads data from your Active Directory you don’t need any administrative privileges. This will work for any domain user.

To make this work you need to:

  1. Install PowerShell and AD cmdlets.
  2. Copy/paste the following function into PowerShell command-line shell before running the commands or add it to your profile (My Documents/WindowsPowerShell/profile.ps1):

function Out-vCard {
$input | ForEach-Object {

    $filename = "c:\" + $_.Name + ".vcf"
    Remove-Item $filename -ErrorAction SilentlyContinue
    add-content -path $filename "BEGIN:VCARD"
    add-content -path $filename "VERSION:2.1"
    add-content -path $filename ("N:" + $_.LastName + ";" + $_.FirstName)
    add-content -path $filename ("FN:" + $_.Name)
    add-content -path $filename ("ORG:" + $_.Company)
    add-content -path $filename ("TITLE:" + $_.Title)
    add-content -path $filename ("TEL;WORK;VOICE:" + $_.PhoneNumber)
    add-content -path $filename ("TEL;HOME;VOICE:" + $_.HomePhone)
    add-content -path $filename ("TEL;CELL;VOICE:" + $_.MobilePhone)
    add-content -path $filename ("TEL;WORK;FAX:" + $_.Fax)
    add-content -path $filename ("ADR;WORK;PREF:" + ";;" + $_.StreetAddress + ";" + $_.PostalCode + " " + $_.City + ";" + $_.co + ";;" + $_.Country)
    add-content -path $filename ("URL;WORK:" + $_.WebPage)
    add-content -path $filename ("EMAIL;PREF;INTERNET:" + $_.Email)
    add-content -path $filename "END:VCARD"


Note that the script is something I put together in 15 minutes to help Jackson, so it still needs a few improvements when I have time:

  1. Need to add an optional parameter for the output folder.
  2. Need to actually look at vCard spec to make sure all attributes translate right.
  3. Need to look whether I need to check whether attributes are present. Does vCard format permit empty values or should their keys be in that case omitted?

Anyways, this seems to solve the task for now, I hope I have a few hours later to make it perfect. Feel free to do so yourself if you are interested.

Tags: , , , , , ,

5 Responses to “Out-vCard: Exporting Outlook Address Book”

  1. 1 Joel "Jaykul" Bennett November 8, 2007 at 3:58 am

    Very nice, I’ll put that to good use.

    Can’t resist saying … you ought to write it as a filter function: use the PROCESS block so you don’t hold up the pipeline 😉 or have a look at my template pipeline script to do it the full featured way.


  2. 2 jdubwillie September 22, 2009 at 2:06 pm

    I’m going to take a long shot here, looking at the age of the post. I have followed the instructions and am very happy with the results. Our company uses the JPEGPHOTO AD object to store a photo of every user. I’m trying to modify the OUT-VCARD function to pull this info in, but I’m not having much luck with it. This is what I have so far:
    add-content -path $filename (“PHOTO; TYPE=JPEG; ENCODING=base64;:” + $_.JPEGPHOTO)

    Any insights or help are appreciated.

  1. 1 Windows PowerShell : Check it out: Out-vCard Trackback on November 7, 2007 at 9:51 pm
  2. 2 MSDN Blog Postings » Check it out: Out-vCard Trackback on November 7, 2007 at 11:45 pm
  3. 3 Powershell Add filepath to ConvertTo-HTML | blindpete.com Trackback on October 8, 2009 at 1:39 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

My Recent Tweets


The posts on this blog are provided “as is” with no warranties and confer no rights. The opinions expressed on this site are mine and mine alone, and do not necessarily represent those of my employer - WSO2 or anyone else for that matter. All trademarks acknowledged.

© 2007-2014 Dmitry Sotnikov

November 2007

%d bloggers like this: