Powershell Script to Export Contacts Note

I have a script that will export outlook contacts. It seems that I am unable to export the notes field.

#New-Item c:\myscripts\output -type directory
New-Item \x.x.x.x\backupemail\users$strname -ItemType directory
New-Item \x.x.x.x\backupemail\users$strname\contacts -ItemType directory
$Outlook=NEW-OBJECT –comobject Outlook.Application


$Contacts | Format-Table FullName,CompanyName,JobTitle,FileAs,Email1Address,WebPage,IMAddress,BusinessTelephoneNumber,BusinessFaxNumber,MobileTelephoneNumber,BusinessAddress,Notes

$properties = ‘FullName’,‘CompanyName’,‘JobTitle’,‘FileAs’,‘Email1Address’,‘WebPage’,‘IMAddress’,‘BusinessTelephoneNumber’,‘BusinessFaxNumber’,‘BusinessAddress’,‘MobileTelephoneNumber’,‘HomeTelephoneNumber’,‘Notes’
$Contacts |
Select-Object -Property $properties |
Export-Csv -NoTypeInformation -Path \x.x.x.x\backupemail\users$strname\contacts\contacts.csv

Thank you in advance

If you did a Select *, you should see all of the attributes and figure out which one is “Notes”. On my client, it appears to be ‘Body’. So, add Body to your Property array

Thank you for the information. I am going to have to play with the Select * and figure out that works so I can get a better fell of things. I am going to assume this will also help with the Calendar if I use a Select * and figure out what fields I need for Properties.
Tested and it worked like a charm.

You can additionally use Get-Member to see what properties are available. However, in this case I wanted to look for my test text in the Note field, so I used Select * to return all properties and values. Another tip is if you have a lot of contacts and just want to see one, then you can use Select * -First 1 to only return the first record and review the properties.

$contacts | Get-Member -MemberType Property
$contacts | Select * -First 1

Ok now I am confused some. I tried both command to see what the output would look like.
When I do ( $contacts | Get-Member -MemberType Property) I see a bunch of fields vs
$contacts | Select * -First 1 (most of these fields are different than the first command).

May I ask what I am not understanding?

Thank you

Hi Mark,

Sorry to revive an old thread but I have a quick question about your script. Everything works great and I am able to export my contacts to a CSV, the only issue I am having is with the headers of the exported file.

Is there anyway to customize the headers when they are exported? Currently when importing back into Outlook, certain fields have to be manually mapped (ie. “ComanyName” isn’t mapped because it is looking for “Company”).

Thanks in advance!

Say you have a CSV like so:

User, Computer, Company

You could do either this (define a new header and skip the original):

Import-CSV C:\Users\rob\desktop\test.csv -Header UserName, ComputerName, CompanyName | Select -Skip 1

or this (calculated expression) :

Import-CSV C:\Users\rob\desktop\test.csv | Select User, Computer, @{Name="CompanyName";Expression={$_.Company}}

Thanks Rob, so it looks like that imported into powershell and displayed all the info and headers correctly (within powershell). How can I get that into another csv file or better yet, do you know how I could import it straight to Outlook?

Exporting is simply calling Export-CSV:

$contacts = Import-CSV C:\Users\rob\desktop\test.csv -Header UserName, ComputerName, CompanyName | Select -Skip 1
$contacts | Export-CSV C:\Users\Rob\Desktop\updated_contacts.csv -NoTypeInformation

If you are looking at importing, you should look at scripts like this: https://gallery.technet.microsoft.com/office/Using-Powershell-to-import-14bef4b8

You’ll notice that they are doing a mapping of columns like Company to CompanyName, so you don’t need to bother with column changes.

Thanks Rob, import/export script worked. The link you provided to import the contacts refers to importing into Exchange though. I’m just looking to import into the Outlook client. I have a couple examples of importing to Outlook, hopefully I can get it working.

Thanks again!