Reputation: 1267
When i run below PS code, it displays list of required attendees, but it shows the display name. What should i do, so that script display's email address instead.
Function Get-OutlookCalendar {
param ( [DateTime] $rangeStart = [DateTime]::Now.AddDays(-2)
, [DateTime] $rangeEnd = [DateTime]::Now.AddDays(+1))
$outlook = New-Object -ComObject Outlook.Application
$session = $outlook.Session
$session.Logon()
$olFolderCalendar = 9
$apptItems = $session.GetDefaultFolder($olFolderCalendar).Items
$apptItems.Sort("[Start]")
$apptItems.IncludeRecurrences = $true
$range = "[End] >= '{0}' AND [Start] <= '{1}'" -f $rangeStart.ToString("g"), $rangeEnd.ToString("g")
$myObject = New-Object System.Object
$result=@()
foreach($appt in $apptItems.Restrict($range)) {
$result+=$appt
}
return $result
}
Get-OutlookCalendar | %{ $_.RequiredAttendees
}
Current output
john, doe; Mark High; Julie, strang
Expected Output
[email protected];[email protected];[email protected]
Please let me know and thank you
Upvotes: 0
Views: 667
Reputation: 66225
RequiredAttendees
corresponds to the PR_DISPLAY_TO
MAPI property, which is a a list of display names.
Use the AppointmentItem.Recipients
collection instead - loop through all recipients and check that Recipient.Type == olTo
(1), read the Recipient.Address
property. You might end up with EX type addresses in case of GAL recipients. In that case, use Recipient.AddressEntry.GetExchangeuser().PrimarySmtpAddress
property.
Upvotes: 1