From ab5acae95c3a1858c5b15059be58bf0c0e397566 Mon Sep 17 00:00:00 2001 From: Przemyslaw Klys Date: Wed, 29 Jul 2020 20:47:41 +0200 Subject: [PATCH] #21 added checking for errors within $Execute content --- Public/Send-TeamsMessage.ps1 | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Public/Send-TeamsMessage.ps1 b/Public/Send-TeamsMessage.ps1 index 831571b..918982e 100644 --- a/Public/Send-TeamsMessage.ps1 +++ b/Public/Send-TeamsMessage.ps1 @@ -10,7 +10,7 @@ function Send-TeamsMessage { [string]$Color, [switch]$HideOriginalBody, [System.Collections.IDictionary[]]$Sections, - [bool] $Supress = $true, + [alias('Supress')][bool] $Suppress = $true, [switch] $ShowErrors ) if ($SectionsInput) { @@ -37,7 +37,7 @@ function Send-TeamsMessage { -MessageSummary $MessageSummary ` -HideOriginalBody:$HideOriginalBody.IsPresent try { - $Execute = Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json; charset=UTF-8' + $Execute = Invoke-RestMethod -Uri $Uri -Method Post -Body $Body -ContentType 'application/json; charset=UTF-8' -ErrorAction Stop } catch { $ErrorMessage = $_.Exception.Message -replace "`n", " " -replace "`r", " " if ($ShowErrors) { @@ -46,8 +46,11 @@ function Send-TeamsMessage { Write-Warning "Send-TeamsMessage - Couldn't send message. Error: $ErrorMessage" } } + if ($Execute -like '*failed*' -or $Execute -like '*error*') { + Write-Warning "Send-TeamsMessage - Couldn't send message. Execute message: $Execute" + } Write-Verbose "Send-TeamsMessage - Execute $Execute Body $Body" - if (-not $Supress) { return $Body } + if (-not $Suppress) { return $Body } } Register-ArgumentCompleter -CommandName Send-TeamsMessage -ParameterName Color -ScriptBlock { $Script:RGBColors.Keys } \ No newline at end of file