1

QUESTION: I'm using Outlook 2019 (on my local computer, no internet, no 365) in Windows 10.
I need to search the user-defined field called "ABC" for value "123" under Powershell.

The aim is to: Show the names of all contacts whose user-defined field "ACB" has the value "123".

WHAT I HAVE TRIED SO FAR: I gather this code identifies all appointments where the Subject contains "TEST":

Add-type -assembly "Microsoft.Office.Interop.Outlook" | out-null
$outlook = New-Object -com Outlook.Application;
$namespace = $outlook.GetNamespace("MAPI");
Register-ObjectEvent -InputObject $outlook -EventName "AdvancedSearchComplete" -Action {
    Write-Host "ADVANCED SEARCH COMPLETE" $Args.Scope
    if ($Args.Results) {  
        foreach ($result in $Args.Results) {
            write-host "=================================================="
            write-host $result.Subject
            write-host $result.ReceivedTime
            write-host $result.SenderName
            write-host "=================================================="
        }
    }
}

Function Get-OutlookInbox {
    $accountsList = $namespace.Folders
    $query = "TEST"
    $filter = "urn:schemas:httpmail:subject LIKE '%"+$query+"%'"

    foreach($account in $accountsList) {
        $scope = $account.FolderPath
        $search = $outlook.AdvancedSearch("'$scope'", $filter, $True)
    }
}

Suppose I have a user defined field called "ABC".

For the person whose name is John Doe, the value for ABC is 123

For the person whose name is Jane Doe, the value for ABC is 456

For the person whose name is Andrew Citizen, the value for ABC is 123

What I want is to search the user defined field ABC for the value "123".

The expected result is:

John Doe

Andrew Citizen

I gather I need to use urn:schemas:contacts

However , how do I query its user-defined fields please? This other piece of code shows me the content of user-defined field ABC for the person whose firstname is Jane.

Function Get-ContactUDF 
{ 
 Add-Type -assembly "Microsoft.Office.Interop.Outlook" -ErrorAction Stop -ErrorVariable "OutlookError" 
 $Outlook = New-Object -comobject Outlook.Application -ErrorAction stop -ErrorVariable "ApplicationError" 

 $objNameSpace = $Outlook.GetNameSpace("MAPI") 
 $objContacts  = $objNameSpace.GetDefaultFolder([Microsoft.Office.Interop.Outlook.OlDefaultFolders]::olFolderContacts) 
 $objContact = $objContacts.Items.Find("[FirstName] = ""Jane""") 
 $objProperty = $objContact.UserProperties.Find("ABC") 
 $objProperty.Value 
} 

What I need is the reverse. Query UserProperties, in order to show the name of the person(s). How do I do it please? (using Powershell). Thanks.

braX
  • 11,506
  • 5
  • 20
  • 33
George
  • 121
  • 7

0 Answers0