mirror of
https://github.com/admindroid-community/powershell-scripts.git
synced 2025-12-17 08:25:20 +00:00
Find Teams Channels with External Members
Due to issue in MS Graph PowerShell (Version 2.27.0 or 2.28.0), API call is used to retrieve external membership.
This commit is contained in:
parent
fa8ebd1b58
commit
95a479bf15
@ -1,7 +1,7 @@
|
|||||||
<#
|
<#
|
||||||
=============================================================================================
|
=============================================================================================
|
||||||
Name: Find All Team Channels with External Members in Microsoft 365
|
Name: Find All Team Channels with External Members in Microsoft 365
|
||||||
Version: 1.0
|
Version: 1.1
|
||||||
Website: o365reports.com
|
Website: o365reports.com
|
||||||
|
|
||||||
Script Highlights:
|
Script Highlights:
|
||||||
@ -16,6 +16,12 @@ Script Highlights:
|
|||||||
6. It can be executed with certificate-based authentication (CBA) too.
|
6. It can be executed with certificate-based authentication (CBA) too.
|
||||||
7. The script is schedular-friendly.
|
7. The script is schedular-friendly.
|
||||||
|
|
||||||
|
Change log:
|
||||||
|
~~~~~~~~~~~
|
||||||
|
V1.0 (Feb 04, 2025) – File created.
|
||||||
|
V1.1 (Jul 07, 2025) – Due to issue in MS Graph PowerShell cmdlet, API call is used to retrieve external membership.
|
||||||
|
|
||||||
|
|
||||||
For detailed Script execution: https://o365reports.com/2025/02/04/get-all-teams-channels-with-external-members/
|
For detailed Script execution: https://o365reports.com/2025/02/04/get-all-teams-channels-with-external-members/
|
||||||
============================================================================================
|
============================================================================================
|
||||||
#>
|
#>
|
||||||
@ -126,12 +132,14 @@ Get-MgTeam -Filter "$($TeamFilter)" -All | ForEach-Object {
|
|||||||
$ExternalUserFound = $false
|
$ExternalUserFound = $false
|
||||||
Write-Progress -Activity "`n Processed Teams count: $ProcessedTeamsCount"`n" Processing Channel: $($ChannelDisplayName) from Team: $($TeamDisplayName)"
|
Write-Progress -Activity "`n Processed Teams count: $ProcessedTeamsCount"`n" Processing Channel: $($ChannelDisplayName) from Team: $($TeamDisplayName)"
|
||||||
|
|
||||||
Get-MgTeamChannelMember -All -Team $TeamId -Channel $ChannelId | ForEach-Object {
|
#Get-MgTeamChannelMember -All -Team $TeamId -Channel $ChannelId | ForEach-Object {
|
||||||
$ExternalMemberTenantId = $_.AdditionalProperties["tenantId"]
|
try {
|
||||||
if (($ExternalMemberTenantId -ne $TenantId) -or ($_.Roles -contains "guest")){
|
(Invoke-MgGraphRequest -Method GET -Uri "/v1.0/teams/$($TeamId)/channels/$($ChannelId)/members" -ErrorAction Stop).value | ForEach-Object {
|
||||||
$ExternalMemberName = $_.DisplayName
|
$ExternalMemberTenantId = $_.tenantId
|
||||||
$ExternalMemberEmail = $_.AdditionalProperties["email"]
|
if (($ExternalMemberTenantId -ne $TenantId) -or ($_.roles -contains "guest")) {
|
||||||
$ExternalMemberGuid = $_.AdditionalProperties["userId"]
|
$ExternalMemberName = $_.displayName
|
||||||
|
$ExternalMemberEmail = $_.email
|
||||||
|
$ExternalMemberGuid = $_.userId
|
||||||
|
|
||||||
if (($MembershipType -notin @("standard","private"))) { $MembershipType = "shared" }
|
if (($MembershipType -notin @("standard","private"))) { $MembershipType = "shared" }
|
||||||
|
|
||||||
@ -150,6 +158,11 @@ Get-MgTeam -Filter "$($TeamFilter)" -All | ForEach-Object {
|
|||||||
$TeamsChannelsWithExternalMembersCount++
|
$TeamsChannelsWithExternalMembersCount++
|
||||||
Print_SummaryReportContent
|
Print_SummaryReportContent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-Host "Error occurred while fetching members for Channel: $($ChannelDisplayName) in Team: $($TeamDisplayName)."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
# Disconnect from Microsoft Graph
|
# Disconnect from Microsoft Graph
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user