No email addresses in Outlook ContactItem via powershell

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)}} 
+5
source share
2 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 
+1
source

I am a little unclear as to what you are linking to achieve. I think you mix two things together - contacts and folders.

I'm not sure if you are trying to get information from Outlook emails or address book (since you are using the folder, I think it is the first). I will gladly fix the solution if it does not solve your problem.

Note. I do not have the same configuration, but close enough: Outlook version: 15.0.0.4420 and PowerShell version: 4.0.30319.

I will try my best to cover what I think you are trying to solve before my very eyes - getting all the email addresses for contacts (adding a subject) from the received emails in the @Outlook "Test Panel".

 # Making sure we have the assembly loaded Add-Type -assembly "Microsoft.Office.Interop.Outlook" # saving the mapping $olFolders = "Microsoft.Office.Interop.Outlook.OlDefaultFolders" -as [type] # new object $Outlook=NEW-OBJECT –comobject Outlook.Application # setting the correct namespace $namespace = $Outlook.GetNameSpace("MAPI") # getting all folders in Outlook inbox $inbox = $namespace.GetDefaultFolder($olFolders::olFolderInbox) # filtering out all but the "Test Folder" $targetFolder = $inbox.Folders.Item("Test Folder") # iteration on email message ForEach($emailMessage in $targetFolder.items) { # getting all the information from the message Write-Verbose -message "From: $($emailMessage.GetProperty) $($emailMessage.SenderEmailAddress)" -Verbose Write-Verbose -message "Subject: $($emailMessage.Subject)" -Verbose } 

Why is the MAPI namespace? Good, because MSDN says so .

I would think that myString -ne '' checks to see if the string is empty.

Yes it is. The difference is that the [String]::IsNullOrEmpty($myString) checks for Null OR Empty in the string. In case you have a value of $null , you can have both true values. It is not empty and is equal to $ null. (for more details see what it means to have the value $ null )

0
source

Source: https://habr.com/ru/post/1273033/


All Articles