Shared channels in Microsoft Teams provide a flexible way for teams to collaborate across different organizations while keeping the conversations and files within a single channel. For Teams administrators, it is crucial to monitor and manage these channels to ensure that they align with organizational policies and security standards.
This article presents a PowerShell script that utilizes Microsoft Graph to list all recently created shared channels across teams. The script provides detailed information such as the creation date of the channel, the team name, the channel name, the number of owners, and the total number of members in each channel.
# Connect to Microsoft Graph
Connect-MgGraph -Scopes "Team.ReadBasic.All" "Channel.ReadBasic.All" "GroupMember.Read.All"
# Define the date range for recently created shared channels (e.g. last 30 days)
$startDate = (Get-Date).AddDays(-30).ToString("yyyy-MM-ddTHH:mm:ssZ")
# Get all teams
$teams = Get-MgTeam -All
# Initialize an array to store the results
$results = @()
# Iterate through each team to find shared channels
foreach ($team in $teams) {
$channels = Get-MgTeamChannel -TeamId $team.Id -Filter "membershipType eq 'shared' and createdDateTime ge $startDate"
foreach ($channel in $channels) {
# Get the list of members in the channel
$members = Get-MgTeamChannelMember -TeamId $team.Id -ChannelId $channel.Id -All
# Count the number of owners
$ownerCount = ($members | Where-Object { $_.Roles -contains "owner" }).Count
# Count the total number of members
$totalMembers = $members.Count
# Store the result in the array
$results += [PSCustomObject]@{
'Channel Created Time' = $channel.CreatedDateTime
'Team Name' = $team.DisplayName
'Channel Name' = $channel.DisplayName
'Owner Count' = $ownerCount
'Total Members' = $totalMembers
}
}
}
# Output the results in a table format
$results | Format-Table -AutoSize
This script efficiently lists all recently created shared channels across Microsoft Teams. Here’s how it operates:
You can enhance this script by adding the following features:
Cause: If you encounter permission errors, the account running the script may lack the necessary permissions in Azure AD to access Microsoft Teams data.
Solution: Ensure that the account has the required permissions. You may need to grant additional permissions in the Azure portal.
Cause: Microsoft Graph API may throttle requests if the script is run against a large number of teams.
Solution: To avoid throttling, consider adding a delay (Start-Sleep) between API calls or handling throttling responses by retrying the request after a pause.
Cause: If the script returns no results, it could mean that no shared channels were created within the specified date range.
Solution: Verify the date range and ensure that the correct scopes are used when running the script.
This PowerShell script provides a practical solution for administrators to monitor the creation of shared channels in Microsoft Teams. By keeping track of newly created shared channels, administrators can ensure that teams collaborate effectively while adhering to organizational policies and security standards. The script can be easily customized and enhanced to meet specific needs, making it a valuable tool in the administration of Microsoft Teams.
This article should serve as a guide to help administrators understand the importance of monitoring shared channels and how to leverage Graph PowerShell for effective Teams management. Feel free to implement and modify the script according to your requirements to keep your Teams environment secure and well-managed.
© m365corner.com. All Rights Reserved. Design by HTML Codex