Apr 16 2020 02:23 AM
Hi everyone
I'm trying to export a list of all teams in our environment along with their associated channels to CSV. I have used the script below previously (although this was around a year ago) but am now getting an error saying that Connect-PnPGraph is not recognised.
I'm not sure what's changed and I can't seem to find any documentation on how I can resolve this issue? I've updated my PnP PowerShell cmdlets but the issue still occurs. The script I'm using is below and I'd really appreciate any help anyone can give. Alternatively, if there is another way I can get this information exported I'd be really interested.
Thanks in advance.
function Export-TeamsList
{
param (
$ExportPath
)
process{
Connect-PnPMicrosoftGraph -Scopes "Group.Read.All","User.ReadBasic.All"
$accesstoken =Get-PnPAccessToken
$group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri "https://graph.microsoft.com/v1.0/groups?`$filter=groupTypes/any(c:c+eq+`'Unified`')" -Method Get
$TeamsList = @()
do
{
foreach($value in $group.value)
{
"Group Name: " + $value.displayName + " Group Type: " + $value.groupTypes
if($value.groupTypes -eq "Unified")
{
$id= $value.id
Try
{
$team = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri https://graph.microsoft.com/beta/Groups/$id/channels -Method Get
"Channel count for " + $value.displayName + " is " + $team.value.id.count
}
Catch
{
"Could not get channels for " + $value.displayName + ". " + $_.Exception.Message
$team = $null
}
If($team.value.id.count -ge 1)
{
$Owner = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri https://graph.microsoft.com/v1.0/Groups/$id/owners -Method Get
$Teams = "" | Select "TeamsName","TeamType","Channelcount","ChannelName","Owners"
$Teams.TeamsName = $value.displayname
$Teams.TeamType = $value.visibility
$Teams.ChannelCount = $team.value.id.count
$Teams.ChannelName = $team.value.displayName -join ";"
$Teams.Owners = $Owner.value.userPrincipalName -join ";"
$TeamsList+= $Teams
$Teams=$null
}
}
}
if ($group.'@odata.nextLink' -eq $null )
{
break
}
else
{
$group = Invoke-RestMethod -Headers @{Authorization = "Bearer $accesstoken"} -Uri $group.'@odata.nextLink' -Method Get
}
}while($true);
$TeamsList |Export-csv $ExportPath -NoTypeInformation
}
}
Export-TeamsList -ExportPath "C:\teamslist.csv"
Apr 16 2020 06:19 AM
SolutionHi @gcjuw84
Here is the link of commands for your reference.
Export all the Teams Channel in Office 365 Tenant
https://gallery.technet.microsoft.com/office/Export-Teams-Channel-de703ad0
With Regards,
Satish U
Apr 22 2020 01:52 PM
That's great thanks. I used the script provided in your second link and added a few lines to also output a count of the channels in each team along with the channel names.
Thanks again for your help.
May 19 2020 02:23 AM
Can you post the final script.
I am having trouble with exporting the channels with this script.
May 19 2020 06:30 AM
No problem, the final script is below. Before running the script you need to make sure you run Connect-MicrosoftTeams and Connect-ExchangeOnline.
Any problems let me know.
$AllTeamsInOrg = (Get-Team).GroupID
$TeamList = @()
Write-Output "This may take a little bit of time... Please sit back, relax and enjoy some GIFs inside of Teams!"
Write-Host ""
Foreach ($Team in $AllTeamsInOrg)
{
$TeamGUID = $Team.ToString()
$TeamGroup = Get-UnifiedGroup -identity $Team.ToString()
$TeamName = (Get-Team | ?{$_.GroupID -eq $Team}).DisplayName
$TeamOwner = (Get-TeamUser -GroupId $Team | ?{$_.Role -eq 'Owner'}).User
$TeamUserCount = ((Get-TeamUser -GroupId $Team).UserID).Count
$TeamGuest = (Get-UnifiedGroupLinks -LinkType Members -identity $Team | ?{$_.Name -match "#EXT#"}).Name
if ($TeamGuest -eq $null)
{
$TeamGuest = "No Guests in Team"
}
$TeamChannels = (Get-TeamChannel -GroupId $Team).DisplayName
$ChannelCount = (Get-TeamChannel -GroupId $Team).ID.Count
$TeamList = $TeamList + [PSCustomObject]@{TeamName = $TeamName; TeamObjectID = $TeamGUID; TeamOwners = $TeamOwner -join ', '; TeamMemberCount = $TeamUserCount; NoOfChannels = $ChannelCount; ChannelNames = $TeamChannels -join ', '; SharePointSite = $TeamGroup.SharePointSiteURL; AccessType = $TeamGroup.AccessType; TeamGuests = $TeamGuest -join ','}
}
#######
$TestPath = test-path -path 'c:\temp'
if ($TestPath -ne $true) {New-Item -ItemType directory -Path 'c:\temp' | Out-Null
write-Host 'Creating directory to write file to c:\temp. Your file is uploaded as TeamsDatav2.csv'}
else {Write-Host "Your file has been uploaded to c:\temp as 'TeamsDatav2.csv'"}
$TeamList | export-csv c:\temp\TeamsDatav2.csv -NoTypeInformation
May 19 2020 07:18 AM
Thanks alot! I'll give it a try!
Nov 26 2020 09:59 AM
I have used the scrip and it is great!
But I see that it only lists the public channels.
Some way you list the public and private?
thanks
Dec 07 2020 02:47 AM
I've just tested this my end and the script seems to show both public and private channels. The Get-TeamChannel should show all channels regardless of whether they're public or private and this is what's used in the script.
If you go into the Teams Admin Centre and view team details via the Manage Teams can you see private channels for a team that has them there?
Feb 01 2021 02:01 PM
Is there a place where I can grab dates of "last's", i.i. Last chat message, last user added, last file added, etc. Our organization implemented Teams with no oversight so there are a lot of orphaned teams.
Thanks!
@gcjuw84
Mar 22 2021 02:46 PM
Thank you for the Script but when I excecute it, I get after about an hour "Access denied"
I did connect-exchangeonline and connect-microsoftteams before.
Also I have the needed Tenant permissions.
Thanks, Philip
Apr 30 2021 02:39 AM
Stuck on:
Creating a new Remote PowerShell session using Modern Authentication for implicit remoting of "Get-UnifiedGroupLinks" command ...
May 04 2021 02:06 AM
Dec 28 2022 12:51 PM
Jan 26 2023 01:30 AM
@colynykalphiacom - were you able to do this? I am currently still exploring this as well.
Feb 06 2023 06:48 AM
Feb 17 2023 08:05 AM