william-r
3/22/2018 - 7:51 PM

Send Microsoft Teams message using Powershell

$server = $(Get-WmiObject Win32_Computersystem).name
$user = "Mr. Robot"
$channel = "#server_chatter"
$emoji = ":desktop_computer:"
$teams_uri = 'office-uri'

function TellTeams{
    $body = @"
    {
        "@type": "MessageCard",
        "@context": "http://schema.org/extensions",
        "themeColor": "ff0000",
        "title": "$server",
        "text":"$user",
        "sections": [{
            "activityTitle": "Server status",
            "activitySubtitle": "Check the systems",
            "facts": [{
                "name": "IIS",
                "value": "up"
            }, {
                "name": "Hyper-V",
                "value": "up"
            }, {
                "name": "MongoDB",
                "value": "up"
            }],
            "markdown": true
        }]
    }
"@
    invoke-webrequest -method Post -uri $teams_uri -contenttype 'application/json' -body $body
}

TellTeams