Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

No email addresses in outlook ContactItem via powershell

When I examine a ContactItem, all of the Email#Address values are null. I have tried settings the value then printing the value. The change is reflected in Outlook, however, no value can be retrieved via PowerShell.

Below are some snippets:

$Outlook=NEW-OBJECT –comobject Outlook.Application
$Contacts=$Outlook.session.GetDefaultFolder(10).items
$Contactsfolders = $Outlook.session.GetDefaultFolder(10).Folders
$testFolder = $Contactsfolders | Where-Object {$_.Name -eq 'Test Folder'}
$testContact = $testFolder.Items(1)

echo $testContact
$testContact.Email1Address = "[email protected]"
echo $testContact

Here is the output of the above execution. Note I've removed some of the uninteresting information to shorten.

First Echo

Application                  : Microsoft.Office.Interop.Outlook.ApplicationClass
Class                        : 40
Session                      : Microsoft.Office.Interop.Outlook.NameSpaceClass
ConversationTopic            : John Doe
FormDescription              : System.__ComObject
GetInspector                 : System.__ComObject
Importance                   : 1
LastModificationTime         : 10/31/2017 5:57:04 PM
MAPIOBJECT                   : System.__ComObject
MessageClass                 : IPM.Contact
OutlookInternalVersion       : 154971
OutlookVersion               : 15.0
Saved                        : True
Sensitivity                  : 0
Size                         : 11614
Subject                      : Bob Doe
UserProperties               : System.__ComObject
Account                      : 
Anniversary                  : 1/1/4501 12:00:00 AM
AssistantName                : 
AssistantTelephoneNumber     : 
Birthday                     : 1/1/4501 12:00:00 AM
CompanyAndFullName           : The Doe Company
                               Doe, Bob
CompanyLastFirstNoSpace      : 
CompanyLastFirstSpaceOnly    : 
CompanyMainTelephoneNumber   : 
CompanyName                  : The Doe Company
ComputerNetworkName          : 
CustomerID                   : 
Department                   : 
Email1Address                : 
Email1AddressType            : 
Email1DisplayName            : 
Email1EntryID                : 
Email2Address                : 
Email2AddressType            : 
Email2DisplayName            : 
Email2EntryID                : 
Email3Address                : 
Email3AddressType            : 
Email3DisplayName            : 
Email3EntryID                : 
FileAs                       : Doe, Bob
FirstName                    : Bob
FTPSite                      : 
FullName                     : Bob Doe
FullNameAndCompany           : Doe, Bob
                               The Doe Company
Gender                       : 0
GovernmentIDNumber           : 
Hobby                        : 
Home2TelephoneNumber         : 
HomeAddress                  : 
HomeAddressCity              : 
HomeAddressCountry           : 
HomeAddressPostalCode        : 
HomeAddressPostOfficeBox     : 
HomeAddressState             : 
HomeAddressStreet            : 
HomeFaxNumber                : 
HomeTelephoneNumber          : 
Initials                     : B.D.
InternetFreeBusyAddress      : 
ISDNNumber                   : 
JobTitle                     : 
Journal                      : False
Language                     : 
LastFirstAndSuffix           : 
LastFirstNoSpace             : 
LastFirstNoSpaceCompany      : 
LastFirstSpaceOnly           : 
LastFirstSpaceOnlyCompany    : 
LastName                     : Doe
LastNameAndFirstName         : Doe, Bob

Second Echo

Application                  : Microsoft.Office.Interop.Outlook.ApplicationClass
Class                        : 40
Session                      : System.__ComObject
Subject                      : Bob Doe
UnRead                       : False
UserProperties               : System.__ComObject
Account                      : 
Anniversary                  : 1/1/4501 12:00:00 AM
AssistantName                : 
AssistantTelephoneNumber     : 
Birthday                     : 1/1/4501 12:00:00 AM
Business2TelephoneNumber     : 
BusinessAddress              : 
BusinessAddressCity          : 
BusinessAddressCountry       : 
BusinessAddressPostalCode    : 
BusinessAddressPostOfficeBox : 
BusinessAddressState         : 
BusinessAddressStreet        : 
BusinessFaxNumber            : 
BusinessHomePage             : 
BusinessTelephoneNumber      : 
CallbackTelephoneNumber      : 
CarTelephoneNumber           : 
Children                     : 
CompanyAndFullName           : The Doe Company
                               Doe, Bob
CompanyLastFirstNoSpace      : 
CompanyLastFirstSpaceOnly    : 
CompanyMainTelephoneNumber   : 
CompanyName                  : The Doe Company
ComputerNetworkName          : 
CustomerID                   : 
Department                   : 
Email1Address                : 
Email1AddressType            : 
Email1DisplayName            : 
Email1EntryID                : 
Email2Address                : 
Email2AddressType            : 
Email2DisplayName            : 
Email2EntryID                : 
Email3Address                : 
Email3AddressType            : 
Email3DisplayName            : 
Email3EntryID                : 
FileAs                       : Doe, Bob
FirstName                    : Bob
FTPSite                      : 
FullName                     : Bob Doe
FullNameAndCompany           : Doe, Bob
                               The Doe Company
Gender                       : 0
GovernmentIDNumber           : 
Hobby                        : 
Home2TelephoneNumber         : 
HomeAddress                  : 
HomeAddressCity              : 
HomeAddressCountry           : 
HomeAddressPostalCode        : 
HomeAddressPostOfficeBox     : 
HomeAddressState             : 
HomeAddressStreet            : 
HomeFaxNumber                : 
HomeTelephoneNumber          : 
Initials                     : B.D.
InternetFreeBusyAddress      : 
ISDNNumber                   : 
JobTitle                     : 
Journal                      : False
Language                     : 
LastFirstAndSuffix           : 
LastFirstNoSpace             : 
LastFirstNoSpaceCompany      : 
LastFirstSpaceOnly           : 
LastFirstSpaceOnlyCompany    : 
LastName                     : Doe
LastNameAndFirstName         : Doe, Bob

Something interesting that I've found while playing with different results and solutions. I've found that both of the below queries results in the same matches which confuses me as I would have thought myString -ne '' is checking if the string is not empty. It appears that myString -ne '' and [String]::IsNullOrEmpty($myString) can both return true which seems impossible, but I think there are some cases where this could happen. Also note that IsNullOrEmpty function is extraordinarily faster.

$Listconstact=$session.GetDefaultFolder(10).Folders | %{$session.GetFolderFromID($_.EntryID).Items | where Email1Address -NE ''}

and

$Listconstact=$session.GetDefaultFolder(10).Folders | %{$session.GetFolderFromID($_.EntryID).Items | where {[String]::IsNullOrEmpty($_.Email1Address)}}

Results from tukan's answer:

VERBOSE: From:
VERBOSE: Subject: How are things
VERBOSE: From:
VERBOSE: Subject: See you soon
VERBOSE: From:
VERBOSE: Subject: Meeting Times
like image 464
galford13x Avatar asked Nov 08 '22 14:11

galford13x


1 Answers

Try Something like this:

$Outlook=NEW-OBJECT –comobject Outlook.Application
$session=$Outlook.session
$Listconstact=$session.GetDefaultFolder(10).Folders | %{$session.GetFolderFromID($_.EntryID).Items | where Email1Address -ne ''}

#only one item
Write-Host "First element mail : $($Listconstact[0].Email1Address)`n`n" 


#All mails
Write-Host "All element mail :"
$Listconstact.Email1Address
like image 187
Esperento57 Avatar answered Nov 15 '22 05:11

Esperento57