Skip to content
Category: Microsoft 365
2020-03-25

How to get full TEAMS Inventory with Powershell

I’m sure all of us who work with Office365 have wondered if it’s possible to extract a report directly from the Teams tool.

So in today’s post, I bring you the answer to this question: Yes, it is possible to extract a report directly from Teams.

We will see how this process works, but to start with, I will show you what is the most common way we have of extracting this type of report:

  • We enter from Teams in the part of Manager Teams. In this console we can manage the Teams that already exist and create new Teams. We can also quickly see the number of Channels, Team Members, Owners, guests and general information about Teams.

  • As we will have checked in the console, to make a good report we have had to go team by team to obtain the data of the channels and users.
  • It is at this point that we may have wondered if there is not an easier way to perform this type of process.

As I mentioned earlier, there is an easier alternative to do this and that is through PowerShell.

First, we will install 2 modules of Teams in our PowerShell:

1. We open PowerShell as Administrator

2. We execute the following commands (We install TEAMS modules)

# Es necesario instalar este Modulo It's mandatory to install this modules 

Install-Module -Name MicrosoftTeams 
# Es necesario instalar este Modulo It's mandatory to install this modules 

Install-Module -Name PSTeams

Once we have the two modules installed we will go on to execute the following script that will return the information from all our computers.

3. We run the “AuditTEAMS.ps1” script

Connect-MicrosoftTeams
$date = Get-Date -UFormat "%Y%m%dT%H%M%S"
$DesktopUser = $env:USERNAME
$ReturnFile = "C:\Users\"+ $DesktopUser +"\Documents\Return\AuditoriasTEAMS_" + $date +".csv"
$GETTEAMS = Get-Team

$Value = "TEAMS;TipodeTEAMS;NombreCanal;DescripcionCanal;UsuariosTeams;NombredelUsuario;RoldeUsuario"
Add-Content -Path $ReturnFile -Value $Value
#$GETTEAMS
foreach($TEAMS in $GETTEAMS)
{
    #$TEAMS.GroupID
    #$TEAMS.DisplayName
    #$TEAMS.Visibility 

    Write-Host "`n`tLos datos de los grupos de TEAMS son:" 
    Write-Host "`tNombre del Equipo de TEAMS: " -NoNewline -ForegroundColor DarkCyan
    Write-Host  $TEAMS.DisplayName -ForegroundColor Green
    Write-Host "`tEl ObjectId del TEAMS: " -NoNewline -ForegroundColor DarkCyan
    Write-Host $TEAMS.GroupID
    Write-Host "`tEl ptipo de TEAMS: " -NoNewline -ForegroundColor DarkCyan
    Write-Host $TEAMS.Visibility 
    
    If($TEAMS.GroupID -ne $Null)
    {
        $GETCHANNELS = Get-TeamChannel -GroupId $TEAMS.GroupID
        foreach($Channels in $GETCHANNELS)
        {
            Write-Host "`tNombre del Canal: " -NoNewline -ForegroundColor DarkGreen
            Write-Host $Channels.DisplayName -ForegroundColor Green
            Write-Host "`tEl Id del Canal: " -NoNewline -ForegroundColor DarkGreen
            Write-Host $Channels.ID
        
            If($Channels.Description -ne "")
            {
                Write-Host "`tLa descripción del Canal: " -NoNewline -ForegroundColor DarkGreen
                Write-Host $Channels.Description -ForegroundColor Green

            }
            $Value = $TEAMS.DisplayName + ";" + $TEAMS.Visibility + ";" + $Channels.DisplayName + ";" + $Channels.Description 
            Add-Content -Path $ReturnFile -Value $Value
        }
        $GETTEAMUSER = Get-TeamUser -GroupId $TEAMS.GroupID
        foreach($TUsers in $GETTEAMUSER)
        {
            $TUsers.User
            $TUsers.Name
            $TUsers.Role
            $VALUE = ";;;;" + $TUsers.User + ";" + $TUsers.Name + ";" + $TUsers.Role
            Write-Host 
            Add-Content -Path $ReturnFile -Value $Value
        }

    }
    Else
    {
        Write-Host "EL ID esta Vacio" -ForegroundColor Red

    }
    
}

In the execution of the script we must take into account that it will leave a report file. “AudiasTEAMS_DateCreation.csv” in the path “C:\Users\”+ $DesktopUser +”\Documents\Return\AuditoriasTEAMS_” + $date +”.csv” with the result obtained by the script that is detailed below.

TEAMS: Here we will get the DisplayName of the TEAMS

TipodeTEAMS: In this Column you get the type of TEAMS it is. (Public or Private)

NombreCanal: Here we will get the DisplayName of the TEAMS Channel

DescripcionCanal: Here we will get the description of the channel if you have it. It is important that when you create a Channel you put the description so that you know how to use the CHANNEL

UsuariosTeams: Here is the user who has access to TEAMS

NombredelUsuario: Here is the TEAMS User Name

RoldeUsuario: Here we will have the role of the users in TEAMS, that is, if they are TEAMS Owners, Members or Guests.

That’s all for today, I hope it will help you to extract your inventory.

If you want us to help your business or company contact us at info@aleson-itc.com or call us at +34 962 681 242.