PowerShellUniversal.Triggers.MSTeams.psm1
function Send-PSUTeamsNotification { <# .SYNOPSIS Send a notification to Microsoft Teams .DESCRIPTION Send a notification to Microsoft Teams from triggers in PowerShell Universal. .PARAMETER Data The trigger data. Generated by PowerShell Universal. .PARAMETER Job The trigger data. Generated by PowerShell Universal. #> param( [Parameter(Mandatory = $true, ParameterSetName = "Data")] $Data, [Parameter(Mandatory = $true, ParameterSetName = "Job")] $Job ) if ($MSteamsWebhookUrl -eq $null) { throw "Please create a variable called `MSteamsWebhookUrl` with the value of your Microsoft Teams Webhook URL" } $Text = "" $Header = "" if ($Job) { $Text = Format-PSUJobDescription -Job $Job $Header = "[$($Job.Id)] $($Job.ScriptFullPath) $($Job.Status.ToString())" } if ($Text -eq "") { Write-Warning "Unknown trigger type." return } $MSteamsData = @{ "@type" = "MessageCard" "@context" = "http://schema.org/extensions" "summary" = "PowerShell Universal Job" "themeColor" = "0078D7" "sections" = @( @{ "activityTitle" = "PowerShell Universal Job" "activitySubtitle" = $Header "activityImage" = "https://www.powershelluniversal.com/assets/img/logo.png" "facts" = @( @{ "name" = "Job ID" "value" = $Job.Id }, @{ "name" = "Script" "value" = $Job.ScriptFullPath }, @{ "name" = "Status" "value" = $Job.Status.ToString() } ) "text" = $Text } ) } $Body = ConvertTo-Json -InputObject $MSteamsData -Depth 5 Invoke-RestMethod -Uri $MSteamsWebhookUrl -Method Post -Body $Body -ContentType "application/json" } |