Send Teams message over unattended script

Iron Contributor


I have some scripting to perform some security tasks, and I would like to send a Teams message to a group with the results of the scripting. So I've got this code, which is working fine:

Connect-MgGraph -Scopes "User.Read.All", "Group.ReadWrite.All,Chat.Read,Chat.ReadWrite,ChatMember.ReadWrite,Chat.ReadBasic"
$chatId = "19:c83c84a4abd142aeb2922f8ed22f4811@thread.v2"
$params = @{
	Body = @{
		Content = "Test Message"
New-MgChatMessage -ChatId $chatId -BodyParameter $params

And everything goes well. But I need an unattended script, so I connecto to MgGraph this way:

Connect-MgGraph -ClientId "clientid" -TenantId "tenantid" -CertificateThumbprint "certificatethumbprint"

But I've got this error:

New-MgChatMessage : Message POST is allowed in application-only context only for import purposes. Refer to for more details.


So it's not an issue with permissions. Anyone faced the same issue and knows how to solve it?



1 Reply

Hi @dmarquesgn 


It's not supported with Application Authentication



What about some Alternatives:

  • Send an Email to a Teams Channel
  • Use a Webhook to send a Message