SHARE
TWEET

Untitled

a guest May 31st, 2019 242 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. |------------------------------------------------------------ Microsoft Teams Report ---------------------------------------------------------------|
  3. | Written by Shaun Wilkinson                                                                                                                        |
  4. | Generates a report showing all teams and users                                                                                                    |
  5. | Requirements: Access to all teams and Team PS module - https://www.powershellgallery.com/packages/MicrosoftTeams                                  |
  6. |---------------------------------------------------------------------------------------------------------------------------------------------------|
  7. #>
  8.  
  9.  
  10. $exportLocation = "C:\users\Shaun.Wilkinson\Desktop\export.csv"
  11.  
  12.  
  13. Connect-MicrosoftTeams
  14.  
  15. # Get all of the team Groups IDs
  16. $AllTeamsInOrg = (Get-Team).GroupID
  17. $TeamReport = @()
  18.  
  19. # Will hold a basic count of user types and teams
  20. $unavailableTeamCount = 0
  21. $knownOwnersCount = 0
  22. $knownMemberCount = 0
  23. $knownGuestCount = 0
  24.  
  25. # Loop through all Group IDs
  26. $currentIndex = 1
  27. ForEach($Team in $AllTeamsInOrg) {
  28.     # Show a nice progress bar as this can take a while
  29.     Write-Progress -Id 0 -Activity "Building report from Microsoft Teams" -Status "$currentIndex of $($allTeamsInOrg.Count)" -PercentComplete (($currentIndex / $allTeamsInOrg.Count) * 100)
  30.  
  31.     # Get properties of the team
  32.     $team = Get-Team -GroupId $Team
  33.  
  34.     # Attempt to get team users, throw error message if no access
  35.     try {
  36.         # Get team members
  37.         $users = Get-TeamUser -GroupId $team.groupID
  38.  
  39.         # foreach user create a line in the report
  40.         ForEach($user in $users) {
  41.             # Maintain a count of user types
  42.             switch($user.Role) {
  43.                 "owner" { $knownOwnersCount++ }
  44.                 "member" { $knownMemberCount++ }
  45.                 "guest" { $knownGuestCount++ }
  46.             }
  47.  
  48.             # Create an object to hold all values
  49.             $teamReportObject = New-Object PSObject -Property @{
  50.                 TeamName = $team.DisplayName
  51.                 Description = $team.Description
  52.                 Archived = $team.Archived
  53.                 Visibility = $team.Visibility
  54.                 User = $user.Name
  55.                 Email = $user.User
  56.                 Role = $user.Role
  57.             }
  58.  
  59.             # Add to the report
  60.             $TeamReport += $teamReportObject
  61.         }
  62.     } catch [Microsoft.TeamsCmdlets.PowerShell.Custom.ErrorHandling.ApiException] {
  63.         Write-Host -ForegroundColor Yellow "No access to $($team.DisplayName) team, cannot generate report"
  64.         $unavailableTeamCount++
  65.     }
  66.  
  67.    
  68.     $currentIndex++
  69. }
  70. Write-Progress -Id 0 -Activity " " -Status " " -Completed
  71.  
  72. # Disconnect from the teams service
  73. Disconnect-MicrosoftTeams
  74.  
  75. # Provide some nice output
  76. Write-Host -ForegroundColor Green "============================================================"
  77. Write-Host -ForegroundColor Green "                Microsoft Teams User Report                 "
  78. Write-Host -ForegroundColor Green ""
  79. Write-Host -ForegroundColor Green "  Count of All Teams - $($AllTeamsInOrg.Count)                "
  80. Write-Host -ForegroundColor Green "  Count of Inaccesible Teams - $($unavailableTeamCount)         "
  81. Write-Host -ForegroundColor Green ""
  82. Write-Host -ForegroundColor Green "  Count of Known Users - $($AllTeamsInOrg.Count)                "
  83. Write-Host -ForegroundColor Green "  Count of Known Owners - $($knownOwnersCount)                "
  84. Write-Host -ForegroundColor Green "  Count of Known Members - $($knownMemberCount)                "
  85. Write-Host -ForegroundColor Green "  Count of Known Guests - $($knownGuestCount)                "
  86.  
  87.  
  88. $TeamReport | Export-CSV $exportLocation -NoTypeInformation
  89. Write-Host -ForegroundColor Green "Exported report to $($exportLocation)"
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top