About Teams logs

ネパリ サンデャ 460 Reputation points
2024-09-04T07:53:27.1766667+00:00

I want to have Teams logs using powershell which contain following information
Teams name, Teams creation date, user name , channel name , channel creation date, channetype,message sent etch
Can it be possible???

Microsoft 365
Microsoft 365
Formerly Office 365, is a line of subscription services offered by Microsoft which adds to and includes the Microsoft Office product line.
4,739 questions
Microsoft Teams
Microsoft Teams
A Microsoft customizable chat-based workspace.
9,954 questions
0 comments No comments
{count} votes

Accepted answer
  1. JimmyYang-MSFT 52,031 Reputation points Microsoft Vendor
    2024-09-05T07:45:55.2366667+00:00

    @ネパリ サンデャ

    Yes, it is possible to retrieve information about Microsoft Teams using PowerShell. You can use modules like MicrosoftTeams and Microsoft.Graph to fetch this data. Below is a high-level overview of how you could approach this task:

    1. Install the necessary PowerShell modules:
      
         Install-Module -Name MicrosoftTeams -Force -AllowClobber
      
         Install-Module -Name Microsoft.Graph -Force -AllowClobber
      
      
    2. Connect to Microsoft Teams and Microsoft Graph:
      
         Import-Module MicrosoftTeams
      
         Import-Module Microsoft.Graph
      
         
      
         # Connect to Microsoft Teams
      
         Connect-MicrosoftTeams
      
         # Connect to Microsoft Graph
      
         Connect-MgGraph -Scopes "Team.ReadBasic.All, Channel.ReadBasic.All, User.Read.All"
      
      
    3. Retrieve Teams Information:
      
         # Get all Teams
      
         $teams = Get-Team
      
         foreach ($team in $teams) {
      
             $teamID = $team.GroupId
      
             $teamName = $team.DisplayName
      
             $teamCreationDate = $team.CreatedDateTime
      
             # Get Team Members
      
             $members = Get-TeamUser -GroupId $teamID
      
             foreach ($member in $members) {
      
                 $userName = $member.UserPrincipalName
      
                 # Get Channels in Team
      
                 $channels = Get-TeamChannel -GroupId $teamID
      
                 foreach ($channel in $channels) {
      
                     $channelName = $channel.DisplayName
      
                     $channelCreationDate = $channel.CreatedDateTime
      
                     $channelType = $channel.MembershipType
      
                     # Retrieve messages (requires Graph API access)
      
                     # $messages = Get-MgTeamChannelMessage -TeamId $teamID -ChannelId $channel.Id
      
                     # Example for output
      
                     [PSCustomObject]@{
      
                         TeamName = $teamName
      
                         TeamCreationDate = $teamCreationDate
      
                         UserName = $userName
      
                         ChannelName = $channelName
      
                         ChannelCreationDate = $channelCreationDate
      
                         ChannelType = $channelType
      
                         # MessagesSent = $messages.Count
      
                     } | Export-Csv -Path "TeamsLog.csv" -Append -NoTypeInformation
      
                 }
      
             }
      
         }
      
      

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.