0
votes

Exchange Management Shell:

[PS] C:\Windows\system32>$AddressBook = Get-PublicFolderItemStatistics -Identity "\Shared Company Address Book"

[PS] C:\Windows\system32>$AddressBook [0] | format-list

RunspaceId           : d8e95055-1f3e-4e7f-a1fc-d5b97ecbcb96
ServerName           : MAILMAN
DatabaseName         : Public Folder Database 0524088380
Subject              : John Q User
PublicFolderName     : \Company Address Book
LastModificationTime : 11/12/2012 2:57:49 PM
CreationTime         : 11/12/2012 2:56:28 PM
HasAttachments       : False
ItemType             : IPM.Contact
MessageSize          : 6.598 KB (6,756 bytes)
Identity             : 000000001A447390AA6611CD9BC800AA002FC45A0900580787449ABF5E4891DD89178938242C0000000250AE00001BE1
                       A5309D57D5439914FD70BDC745C100000B8942FD0000
MapiIdentity         : 000000001A447390AA6611CD9BC800AA002FC45A0900580787449ABF5E4891DD89178938242C0000000250AE00001BE1
                       A5309D57D5439914FD70BDC745C100000B8942FD0000
OriginatingServer    : mailman.company.com
IsValid              : True

[PS] C:\Windows\system32>

Okay... I'm trying to export the contacts in an Exchange Server 2010 Contact List. I can not, for the world of me, figure out how to get the "Data" out of this stupid thing.

If I do $AddressBook | Format-List, it lists all the contacts, so I'm know I'm in the right ballpark.

how can I get all of the information out of this list? Last Name, First Name, Email Address, Business Phone, etc.

3

3 Answers

3
votes

This is an old post, but I have the same issue for a couple days and was unable to figure it out. So, I opted to use the road @WernerCD used and would like to add my PowerShell script that could help you in the case that you decide to go down this path.

Before starting, allow me to explain my issue. We have multiple folders with contacts in it. These contacts contain User Defined Fields that due to migration issues, were not added to their containing folder. While we use Outlook, we need to be able to see these fields on the current view. However, when we try to add the UDF columns, it only allows us to use the "User-defined fields in folder", which is empty.

Below is the PowerShell script that will check a public folder (and its subfolders) within Outlook, check every contact UserProperties (Equivalent for UDF), put them into an array, then it will check if each contact's UDF exist on its containing folder (UserDefinedProperties), and if it doesn't exist, it will added it as a Text field without a value.

Please keep in mind that all our contact folders are under a folder called Shared Contacts Folder.

Code

# Connection to Outlook
$Outlook       = New-Object -com Outlook.Application 
$Namespace     = $outlook.GetNamespace("MAPI") 

# "Location" of public folders (Change [email protected])
$PublicFolder  = $Namespace.Folders.Item("Public Folders - [email protected]")
$PublicFolders = $PublicFolder.Folders.Item("All Public Folders")

# Folder that you would like to check. We will check Shared Contacts under Shared Contacts Folder
$SharedContactsFolder   = $PublicFolders.Folders.Item("Shared Contacts Folder")
$SharedContacts   = $SharedContactsFolder.Folders.Item("Shared Contacts")

Write-Host ("<----------------------------------------------------------->") -foreground Yellow

function CheckContacts($MyFolder){

    # Check if this folder has subfolder
    If ( $MyFolder.Folders.Count -gt 0) {

        Write-Host ("Folder '" + $MyFolder.Name + "' contains subfolders ("  + $MyFolder.Folders.Count + ")")  -BackgroundColor Yellow -foreground DarkBlue

        Foreach ( $Subfolder in $MyFolder.Folders ) {

            CheckContacts($Subfolder)

        }

    }

    Write-Host ("Working on folder: " + $MyFolder.Name)  -BackgroundColor White -foreground DarkBlue

    $All_UDF = @()

    # Check User Defined Fields (UDF) for each contact and add them to array
    foreach ( $Contacts in $MyFolder.Items ) {

        foreach ( $UDF in $Contacts.UserProperties ) {

            # Check if field was previously added to array
            If ($All_UDF -notcontains $UDF.Name) {
                $All_UDF += $UDF.Name
            }

        }

    }

    # Add all UDF to Folder's UDF
    Write-Host ("We will add the following UDF into '" + $MyFolder.Name + "': ") -foreground Green
    Write-Host ($All_UDF -join "`n") -foreground Green

    Foreach ( $UDF in $All_UDF ){

        # Only add if UDF does not exist on folder's UDF
        if( (CheckFolderUDF $MyFolder $UDF) -eq $false) {
            # Add - Always add UDF as Text field (1)
            Write-Host ("Adding '" + $UDF + "' to '" + $MyFolder.Name + "'")
            $MyFolder.UserDefinedProperties.Add($UDF, 1)
        }else{
            Write-Host ("Already present: " + $UDF)
        }

    }

    Write-Host ("<----------------------------------------------------------->") -foreground Yellow
}

Function CheckFolderUDF ( $MyFolder, $MyUDFName ) {
    $Result = $false

    Foreach ( $Folder_UDF in $MyFolder.UserDefinedProperties ){

        If ( $Folder_UDF.Name -eq $MyUDFName ) {
            $Result = $true
            break
        }

    }

    return $Result

}

# Start - Check Shared Contacts
CheckContacts($SharedContacts) 

How do I run/test this code?

1) Open Windows PowerShell ISE (within Windows).

2) Copy the code above and paste it into the PowerShell ISE window.

3) Read and understand the code.

4) Modify as needed.

P.S.: I tried to add this a "comment", but I don't have enough points.

1
votes

After much pain and suffering... and stumbling upon [this post]. This is in Powershell (not Exchange Powershell Console) and from my computer (not server MailMan):

$Outlook       = New-Object -com Outlook.Application 
$Namespace     = $outlook.GetNamespace("MAPI") 
$PublicFolder  = $Namespace.Folders.Item("Public Folders - [email protected]")
$PublicFolders = $PublicFolder.Folders.Item("All Public Folders")
$AddressBook   = $PublicFolders.Folders.Item("Company Address Book")
$Contacts      = $AddressBook.Items
$Contacts | Select FullName

This actually pulls the contact information. I'm still looking at how to do it on the server side (Exchange Powershell Console), but this should be a good foundation to select the desired fields and push them into the database as I need.

I figure if I can figure out how to get the "Public Folders - [email protected]", I should be able to do the same thing on the server.

I also assume there is an easier way to do this (maybe by pull path, instead of one part at a time), but this does work.

Now to find out how to get UserDefinedFields....

0
votes

Why don't you use Get-Contact instead of Get-PublicFolderItemStatistics?