Skip to content

Instantly share code, notes, and snippets.

@smaglio81
Created January 28, 2019 00:36
function Send-Notification {
param(
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string] $Component,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[ValidateSet("Debug","Information","Warning","Error","Validation")]
[string] $MessageType,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string[]] $Tags,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string] $ID,
[Parameter(Mandatory = $true, ValueFromPipelineByPropertyName = $true)]
[string] $Message,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[string] $CreatedBy = $env:USERNAME,
[Parameter(ValueFromPipelineByPropertyName = $true)]
[DateTime] $CreatedDate = [DateTime]::Now
)
$notification = New-Notification @PSBoundParameters
. "$($global:Notifications.AMModule)\Save-Notification" -Notification $notification
$subscriptions = . "$($global:Notifications.CMModule)\Select-MatchingSubscription" `
-Component $Component `
-MessageType $MessageType `
-Tags $Tags
foreach($subscription in $subscriptions) {
$senderModule = "NS{0}" -f $subscription.ContactType
if((Get-Module $senderModule) -eq $null) {
throw (
("Send-Notification: Sub-module '{0}' needs to be loaded before notifications " +
"can be sent to the {1} contact type. If this is an unknown contact type, please " +
"ensure the subscription which contains that contact type is updated to a known type.") -f
$senderModule, $subscription.ContactType
)
}
. "$senderModule\Send-NotificationToSubscription" -Notification $notification -Subscription $subscription
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment