Write-Host"`nImportant: Microsoft Graph module is unavailable. It is mandatory to have this module installed in the system to run the script successfully."
$confirm=Read-Host"Are you sure you want to install Microsoft Graph module? [Y] Yes [N] No"
Write-Host"Connected to Microsoft Graph PowerShell using account: $(($Script:MgContext).Account)"
}else{
Write-Host"Failed to connect to Microsoft Graph."-ForegroundColorRed
Exit
}
}
# Print Summary Report
FunctionPrint_SummaryReportContent{
$Result=@{'Team Name'=$TeamDisplayName;'Channel Name'=$ChannelDisplayName;'Membership Type'=$MembershipType;'External Members Count'=$ExternalMembersCount;'External Members'=$ExternalMembers;'Team Id'=$TeamId;'Channel Id'=$ChannelId;}
$Results=New-ObjectPSObject-Property$Result
$Results|Select-Object'Team Name','Channel Name','Membership Type','External Members Count','External Members','Team Id','Channel Id'|Export-Csv-Path$SummaryReport-Notype-Append
}
# Print Detailed Output
FunctionPrint_DetailedReportContent{
$Result=@{'Team Name'=$TeamDisplayName;'Channel Name'=$ChannelDisplayName;'Membership Type'=$MembershipType;'External Member Name'=$ExternalMemberName;'External Member Email'=$ExternalMemberEmail;'External Member Id'=$ExternalMemberGuid;}
$Results=New-ObjectPSObject-Property$Result
$Results|Select-Object'Team Name','Channel Name','Membership Type','External Member Name','External Member Email','External Member Id'|Export-Csv-Path$DetailedReport-Notype-Append
}
# Connecting to the Microsoft Graph PowerShell Module
Connect_ToMgGraph
# Get all teams channels with external members in Microsoft 365
Write-Host"~~ Check out "-NoNewline-ForegroundColorGreen;Write-Host"admindroid.com"-ForegroundColorYellow-NoNewline;Write-Host" to get access to 1900+ Microsoft 365 reports. ~~"-ForegroundColorGreen
# Open output file after execution
if((Test-Path-Path$DetailedReport)-eq"True"){
Write-Host`n"$TeamsChannelsWithExternalMembersCount teams channels are found with external members."
Write-Host`n" The summary report available in: "-NoNewline-ForegroundColorYellow;Write-Host$SummaryReport
Write-Host`n" The detailed report available in: "-NoNewline-ForegroundColorYellow;Write-Host$DetailedReport
$Prompt=New-Object-ComObjectwscript.shell
$UserInput=$Prompt.popup("Do you want to open output files?",`0,"Open Output File",4)
If($UserInput-eq6){
Invoke-Item"$SummaryReport"
Invoke-Item"$DetailedReport"
}
}
else{
Write-Host`n"No teams channels are found with external members."-ForegroundColorRed