Skip to content

Commit b002325

Browse files
authored
Merge pull request #1 from Sekers/develop
Develop into Main 1.0.7
2 parents c3ca431 + 1566f1e commit b002325

File tree

5 files changed

+82
-38
lines changed

5 files changed

+82
-38
lines changed

CHANGELOG.md

+13
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,18 @@
11
# Changelog for ScriptMessage PowerShell Module
22

3+
## [1.0.7](https://github.com/Sekers/ScriptMessage/tree/1.0.7) - (2024-12-26)
4+
5+
### Features
6+
7+
- New messaging class "MessageServiceType" and corresponding parameters for the Send-ScriptMessage Cmdlet to allow multiple/combined service & type parameters in one call.
8+
9+
### Other
10+
11+
- Results returned from Send-ScriptMessage has recipients adjusted from Hashtables to PSCustomObjects. This better handles collections (arrays) of addresses than hashtables being returned. Originally it was hashtables to mimic what Graph uses but that's not great for our purpose.
12+
13+
Author: [**@Sekers**](https://github.com/Sekers)
14+
15+
---
316
## [1.0.6](https://github.com/Sekers/ScriptMessage/tree/1.0.6) - (2024-12-19)
417

518
### Fixes

ScriptMessage/Public/Send-ScriptMessage.ps1

+32-14
Original file line numberDiff line numberDiff line change
@@ -135,17 +135,26 @@ function Send-ScriptMessage
135135
[CmdletBinding()]
136136
param(
137137
[Parameter(
138+
ParameterSetName = 'ServiceAndTypeSeparate',
138139
Mandatory = $true,
139140
ValueFromPipeline = $true,
140141
ValueFromPipelineByPropertyName = $true)]
141142
[MessagingService[]]$Service,
142143

143144
[Parameter(
145+
ParameterSetName = 'ServiceAndTypeSeparate',
144146
Mandatory = $false,
145147
ValueFromPipeline = $true,
146148
ValueFromPipelineByPropertyName = $true)]
147149
[MessageType[]]$Type = 'Mail',
148150

151+
[Parameter(
152+
ParameterSetName = 'ServiceAndTypeCombined',
153+
Mandatory = $true,
154+
ValueFromPipeline = $true,
155+
ValueFromPipelineByPropertyName = $true)]
156+
[MessageServiceType[]]$ServiceType,
157+
149158
[Parameter(
150159
Mandatory = $true,
151160
ValueFromPipeline = $true,
@@ -212,17 +221,19 @@ function Send-ScriptMessage
212221
)
213222

214223
begin
224+
{
225+
# Set the necessary configuration variables.
226+
$ScriptMessageConfig = Get-ScriptMessageConfig
227+
}
228+
229+
process
215230
{
216231
# Make sure that at least one of, To, CC, or BCC is provided.
217232
if ([string]::IsNullOrEmpty($To) -and [string]::IsNullOrEmpty($CC) -and [string]::IsNullOrEmpty($BCC))
218233
{
219234
throw 'Please provide at least one parameter value for any of the following: To, CC, or BCC'
220235
}
221236

222-
# Remove Message Service & Message Type duplicates.
223-
$Service = $Service | Select-Object -Unique
224-
$Type = $Type | Select-Object -Unique
225-
226237
# Convert recipient types into properly formatted PSObject.
227238
$From = ConvertTo-ScriptMessageRecipientObject -Recipient $From # Note that From is NOT an array. There should only be one.
228239
[array]$ReplyTo = ConvertTo-ScriptMessageRecipientObject -Recipient $ReplyTo
@@ -233,23 +244,30 @@ function Send-ScriptMessage
233244
# Convert body into properly formatted PSObject
234245
$Body = ConvertTo-ScriptMessageBodyObject -Body $Body
235246

236-
# Set the necessary configuration variables.
237-
$ScriptMessageConfig = Get-ScriptMessageConfig
238-
}
247+
if ($null -ne $Service) # If ServiceAndTypeSeparate
248+
{
249+
# Remove message service & message type duplicates.
250+
$Service = $Service | Select-Object -Unique
251+
$Type = $Type | Select-Object -Unique
239252

240-
process
241-
{
242-
foreach ($serviceItem in $Service)
253+
# Create the ServiceType class object\hash.
254+
[MessageServiceType]$ServiceType = @{
255+
Service = $Service
256+
Type = $Type
257+
}
258+
}
259+
260+
foreach ($serviceTypeObj in $ServiceType)
243261
{
244262
# Set the connection parameters.
245263
$ConnectionParameters = @{
246-
ServiceConfig = $ScriptMessageConfig.$serviceItem
264+
ServiceConfig = $ScriptMessageConfig.$($serviceTypeObj.Service)
247265
}
248266

249267
# Connect to the messaging service, if necessary (e.g., API service).
250-
Connect-ScriptMessage -Service $serviceItem -ErrorAction Stop
268+
Connect-ScriptMessage -Service $($serviceTypeObj.Service) -ErrorAction Stop
251269

252-
switch ($serviceItem)
270+
switch ($($serviceTypeObj.Service))
253271
{
254272
'MgGraph' {
255273
$SendMessageParameters = [ordered]@{
@@ -263,7 +281,7 @@ function Send-ScriptMessage
263281
Body = $Body
264282
Attachment = $Attachment
265283
SenderId = $SenderId
266-
Type = $Type
284+
Type = $serviceTypeObj.Type
267285
}
268286

269287
Send-ScriptMessage_MgGraph @SendMessageParameters

ScriptMessage/ScriptMessage.psd1

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
RootModule = 'ScriptMessage.psm1'
1313

1414
# Version number of this module.
15-
ModuleVersion = '1.0.6'
15+
ModuleVersion = '1.0.7'
1616

1717
# Supported PSEditions
1818
CompatiblePSEditions = @('Desktop','Core')

ScriptMessage/ScriptMessage.psm1

+7-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# Public Enum
44
# Name: MessagingService
55
enum MessagingService {
6-
MgGraph
6+
MgGraph
77
}
88

99
# Public Enum
@@ -13,6 +13,12 @@ enum MessageType {
1313
Chat
1414
}
1515

16+
# Public Class
17+
class MessageServiceType {
18+
[MessagingService[]]$Service
19+
[MessageType[]]$Type
20+
}
21+
1622
# Import Private Functions
1723
$ScriptMessageFunctions = @(Get-ChildItem -Path $PSScriptRoot\Private\*.ps1)
1824
Foreach($ScriptMessageFunction in $ScriptMessageFunctions)

ScriptMessage/Services/MgGraph.ps1

+29-22
Original file line numberDiff line numberDiff line change
@@ -270,9 +270,6 @@ function Send-ScriptMessage_MgGraph
270270
{
271271
# Set the Service ID.
272272
$ServiceId = 'MgGraph'
273-
274-
# Set the necessary configuration variables.
275-
$ScriptMessageConfig = Get-ScriptMessageConfig
276273
}
277274

278275
process
@@ -329,26 +326,36 @@ function Send-ScriptMessage_MgGraph
329326
$SendEmailMessageResult = Send-MgUserMail -UserId $SenderId -BodyParameter $EmailParams -PassThru
330327

331328
# Collect Return Info
332-
$SendScriptMessageResult = [ordered]@{}
333-
$SendScriptMessageResult.MessageService = $ServiceId
334-
$SendScriptMessageResult.MessageType = $typeItem
335-
$SendScriptMessageResult.Status = $SendEmailMessageResult # The SDK only returns $true and nothing else (and only that because of the 'PassThru')
336-
$SendScriptMessageResult.Error = $null
337-
$SendScriptMessageResult.SentFrom = @{}
338-
$SendScriptMessageResult.SentFrom.Name = $From.Name
339-
$SendScriptMessageResult.SentFrom.Address = $From.AddressObj
340-
$SendScriptMessageResult.Recipients = [ordered]@{}
341-
$SendScriptMessageResult.Recipients.All = $null # Create this before populating for ordered list purposes.
342-
[array]$SendScriptMessageResult.Recipients.To = @(($Message.To).EmailAddress | Sort-Object $_.Value)
343-
[array]$SendScriptMessageResult.Recipients.CC = @(($Message.CC).EmailAddress | Sort-Object $_.Value)
344-
[array]$SendScriptMessageResult.Recipients.BCC = @(($Message.BCC).EmailAddress | Sort-Object $_.Value)
345-
[array]$SendScriptMessageResult.Recipients.All = @( # Since Address is also a PSMethod we need to do some fun stuff (List<psobject> doesn't have a method called Address) so we don't get the dreaded 'OverloadDefinitions'.
346-
[System.Linq.Enumerable]::ToList([psobject[]]$SendScriptMessageResult.Recipients.To).Address
347-
[System.Linq.Enumerable]::ToList([psobject[]]$SendScriptMessageResult.Recipients.CC).Address
348-
[System.Linq.Enumerable]::ToList([psobject[]]$SendScriptMessageResult.Recipients.BCC).Address
329+
$SendScriptMessageResult_SentFrom = [PSCustomObject]@{
330+
Name = $From.Name
331+
Address = $From.AddressObj
332+
}
333+
334+
[array]$SendScriptMessageResult_Recipients_To = foreach ($i in ($Message.To).EmailAddress) {[PSCustomObject]$i} # Converts hashtables to PSCustomObjects
335+
[array]$SendScriptMessageResult_Recipients_CC = foreach ($i in ($Message.CC).EmailAddress) {[PSCustomObject]$i} # Converts hashtables to PSCustomObjects
336+
[array]$SendScriptMessageResult_Recipients_BCC = foreach ($i in ($Message.BCC).EmailAddress) {[PSCustomObject]$i} # Converts hashtables to PSCustomObjects
337+
[array]$SendScriptMessageResult_Recipients_All = @( # Since Address is also a PSMethod we need to do some fun stuff (List<psobject> doesn't have a method called Address) so we don't get the dreaded 'OverloadDefinitions'.
338+
[System.Linq.Enumerable]::ToList([PSObject[]]$SendScriptMessageResult_Recipients_To).Address
339+
[System.Linq.Enumerable]::ToList([PSObject[]]$SendScriptMessageResult_Recipients_CC).Address
340+
[System.Linq.Enumerable]::ToList([PSObject[]]$SendScriptMessageResult_Recipients_BCC).Address
349341
)
350-
[array]$SendScriptMessageResult.Recipients.All = $SendScriptMessageResult.Recipients.All | Sort-Object -Unique # Remove duplicate items.
351-
342+
[array]$SendScriptMessageResult_Recipients_All = $SendScriptMessageResult_Recipients_All | Sort-Object -Unique # Remove duplicate items.
343+
$SendScriptMessageResult_Recipients = [PSCustomObject]@{
344+
To = $SendScriptMessageResult_Recipients_To
345+
CC = $SendScriptMessageResult_Recipients_CC
346+
BCC = $SendScriptMessageResult_Recipients_BCC
347+
All = $SendScriptMessageResult_Recipients_All
348+
}
349+
350+
$SendScriptMessageResult = [PSCustomObject]@{
351+
MessageService = $ServiceId
352+
MessageType = $typeItem
353+
Status = $SendEmailMessageResult # The SDK only returns $true and nothing else (and only that because of the 'PassThru')
354+
Error = $null
355+
SentFrom = $SendScriptMessageResult_SentFrom
356+
Recipients = $SendScriptMessageResult_Recipients
357+
}
358+
352359
# If successful, output result info.
353360
$SendScriptMessageResult
354361
}

0 commit comments

Comments
 (0)