When I examine ContactItem , all email address values ​​are NULL. I tried to set the value and then print the value. This change is reflected in Outlook, but no value can be obtained through 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 = " BobDoe3@doe.com " echo $testContact
Here is the result of the execution above. Note. I cut some of the uninteresting information to cut.
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 : BD 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 : BD InternetFreeBusyAddress : ISDNNumber : JobTitle : Journal : False Language : LastFirstAndSuffix : LastFirstNoSpace : LastFirstNoSpaceCompany : LastFirstSpaceOnly : LastFirstSpaceOnlyCompany : LastName : Doe LastNameAndFirstName : Doe, Bob
Something interesting that I found playing with different results and solutions. I found that both of the following queries lead to the same matches, which confuses me, as I thought, myString -ne '' checks to see if the string is empty. It looks like myString -ne '' and [String]::IsNullOrEmpty($myString) can return true, which seems impossible, but I think there are times when this can happen. Also note that the IsNullOrEmpty function IsNullOrEmpty unusually 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)}}
source share