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 = "BobDoe3@doe.com"
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
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
I'm kind of fuzzy on what you are tying to achieve. To me it seems you are mixing two things together - contacts & folders.
I'm not sure if you are trying to get information from Outlook emails or Address book (since you are using folder I guess it is the first). I'll gladly rectify the solution if it is not solving your issue.
Note: I don't have identical configuration but close enough: Outlook version: 15.0.0.4420 and PowerShell version: 4.0.30319 .
I'll try my best to cover what I think you are trying to solve in my eyes - Getting all contacts' email addresses (adding also subject) from received emails in "Test Folder" @Outlook .
# 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 MAPI namespace? Well because the MSDN says so .
I would have thought myString -ne '' is checking if the string is not empty.
Yes it does do that. The difference is that the method [String]::IsNullOrEmpty($myString)
is checking for Null OR Empty in a string. In case, when you have a $null
value then you can have both true. It is not empty and is $null. (for more see what does it mean to have a $null value)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.