Replies: 1 comment
-
Instead of a Class, this could also be improved with a function still resulting in fewer lines of PowerShell. The following is a proposed idea. function New-SMEXCOMessage ($ExchangeMessage)
{
$smexcoMessage = New-Object System.Object
$smexcoMessage | Add-Member -type NoteProperty -name From -value $ExchangeMessage.From.Address
$smexcoMessage | Add-Member -type NoteProperty -name To -value $ExchangeMessage.ToRecipients
$smexcoMessage | Add-Member -type NoteProperty -name CC -value $ExchangeMessage.CcRecipients
$smexcoMessage | Add-Member -type NoteProperty -name Subject -value $ExchangeMessage.Subject
$smexcoMessage | Add-Member -type NoteProperty -name Attachments -value $ExchangeMessage.Attachments
$smexcoMessage | Add-Member -type NoteProperty -name Body -value $ExchangeMessage.Body.Text
$smexcoMessage | Add-Member -type NoteProperty -name DateTimeSent -Value $ExchangeMessage.DateTimeSent
$smexcoMessage | Add-Member -type NoteProperty -name DateTimeReceived -Value $ExchangeMessage.DateTimeReceived
$smexcoMessage | Add-Member -type NoteProperty -name ID -Value $ExchangeMessage.ID
$smexcoMessage | Add-Member -type NoteProperty -name ConversationID -Value $ExchangeMessage.ConversationID
$smexcoMessage | Add-Member -type NoteProperty -name ConversationTopic -Value $ExchangeMessage.ConversationTopic
$smexcoMessage | Add-Member -type NoteProperty -name ItemClass -Value $ExchangeMessage.ItemClass
#if these properties exist, it's an Appointment
if ($ExchangeMessage.Start) {$smexcoMessage | Add-Member -type NoteProperty -name StartTime -Value $ExchangeMessage.Start}
if ($ExchangeMessage.End) {$smexcoMessage | Add-Member -type NoteProperty -name EndTime -Value $ExchangeMessage.End}
return $smexcoMessage
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
With each new message class introduced, a doubling of efforts is created with constant re-use of the same PSCustomObjects created (e.g. $email and $calAppt).
It would make more sense to throw these into a PowerShell class to increase code re-use and would introduce the need to raise the minimum PowerShell version of this script/runbook to v5.
Beta Was this translation helpful? Give feedback.
All reactions