Product: PowerShell Universal Version: 5.5.5
I am new to using PowerShell Universal and I am setting up notifications. I installed PowerShellUniversal.Triggers.MSTeams and set up a trigger for job failed. When it tries to run the function, I get the following error.
The term 'Format-PSUJobDescription' is not recognized as a name of a cmdlet, function, script file, or executable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. at Send-PSUTeamsNotification, C:\ProgramData\UniversalAutomation\Repository\Modules\PowerShellUniversal.Triggers.MSTeams\1.0.0\PowerShellUniversal.Triggers.MSTeams.psm1: line 31 at <ScriptBlock>, <No file>: line 1 Unknown trigger type.
I could not really find anything about this on here. Is there another module I should have installed?
To get this working, I had to change one thing in PowerShellUniversal.Triggers.MSTeams.psm1
function Send-PSUTeamsNotification {
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 #This has to be changed to $Text = $($Job.StatusDescription)
$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"
}I had to change $text = Format-PSUJobDescription -job $Job to $Text = $($Job.StatusDescription). After this, the notifications went through fine.