Saturday, September 9, 2023

Get Team chat details using Microsoft.Graph

----
1. Install-Module Microsoft.Graph
2. Connect MicrosoftGraph API  Module
3. Get chat id using Get-MgChat commandlet
4. Get Chat member for particular chat id using Get-MgChatMember
5. Get chat messages\Chat history for particular chat using Get-MgChatMessage
```sh
Install-Module Microsoft.Graph
Import-Module Microsoft.Graph

Connect-MgGraph

<# "Get-MgChat" ,"Get-MgChatMember","Get-MgChatMessage" | 
& {Process{Find-mggraphcommand Get-MgChat|select permissions|
&{Process{Connect-MgGraph -Scopes $_}} }} #>

$displayName="< Display Name>"
$user=Get-MgUser  -Filter "DisplayName eq '$displayName'"

Get-MgChat  | select Topic,ChatType,id,WebUrl

$chatID=$(Get-MgChat  | select id -First 1).id


#Get all Chat members for chat 
Get-MgChatMember -ChatId $chatID | select AdditionalProperties).AdditionalProperties

#Get ACS chat members
(Get-MgChatMember -ChatId $chatID |Where DisplayName -eq raz| select AdditionalProperties).AdditionalProperties

#Get AAD chat members
(Get-MgChatMember -ChatId $chatID |Where DisplayName -eq 'razesh'| select AdditionalProperties).AdditionalProperties

#Get chat messages for chat id

Get-MgChatMessage -ChatId $chatID |& {Process{ if ($($_.From.User.DisplayName)) {Write-host "From :$($_.From.User.DisplayName)" ;"Message:$($_.body.Content)";  Write-Host ""}}}

```

No comments:

Post a Comment