PowerTip: List Outlook Contacts with PowerShell

PowerTip: List Outlook Contacts with PowerShell

  • Comments 6
  • Likes

Summary: Use Windows PowerShell to list contacts in Microsoft Outlook.

Hey, Scripting Guy! Question How can I use Windows PowerShell to programmatically connect to Outlook to get the Contacts list?

Hey, Scripting Guy! Answer Connect by using ComObject, and select the objects you need:

$Outlook=NEW-OBJECT –comobject Outlook.Application

$Contacts=$Outlook.session.GetDefaultFolder(10).items

$Contacts | Format-Table FullName,MobileTelephoneNumber,Email1Address

Your comment has been posted.   Close
Thank you, your comment requires moderation so it may take a while to appear.   Close
Leave a Comment
  • Nope. Too easy. Now load them into SharePoint on O365. It takes about three more steps.

  • Hello,
    How can I export this contacts to msg files?
    THX

  • How would I delete the contacts? I tried changing the last line to "$Contacts | Remove-Item" but it didn't work. The user has 63,000 contacts that were sync'd with CRM so doing this manually would take too long. Any suggestions?

  • What I am having problems with is. I am trying to do some data mining, with something like this:

    #This is the Outlook "get your inbox" stuff that store it all in a $inbox variable.
    $olFolderInbox = 6
    $outlook = new-object -com outlook.application;
    $ns = $outlook.GetNameSpace("MAPI");
    $inbox = $ns.GetDefaultFolder($olFolderInbox)

    #Loops through the variable and outputs the fields you select to the CSV.
    foreach ($b in $inbox.Items)
    {
    $b | select sendername,subject,Senton | export-csv -Path $outputFile -NoTypeInformation -Append
    }


    Seems to me that the number 6 equals INBOX.
    Just like in your script 10 equals Contacts.

    I would like to run a command like what you have here, that will identify the numbers of each folder within a users mailbox.

    for instance:
    John Doe
    -Inbox
    --2014
    --2013
    -Sent Items
    -Deleted Items
    -Contacts

    So a script I would run would tell me what number to use for the subfolder in Inbox called 2014

  • # loop throughinbox and export selected properties
    $inbox.Items |
    select sendername,subject,Senton |
    export-csv -Path $outputFile -NoTypeInformation -Append

    # get all default folder names and get enum for 'Sent Items'
    add-type -AssemblyName Microsoft.Office.Interop.Outlook
    [Enum]::GetNames([Microsoft.Office.Interop.Outlook.olDefaultFolders])
    [Microsoft.Office.Interop.Outlook.olDefaultFolders]::olFolderSentMail