Some fun with teams PowerShell module

The estimated reading time 2 minutes

you may have found my old article from june 1st 2018 LINK. Some time has passed since this article was released. Yes I know there is a overview in Teams Admin Center, but I thought it would be nice to do this and some kind more via PowerShell Module. So I picked up the script and build it again with the organic PowerShell Module for Teams.

Before let’s check permissions of the executing user. You need to be Teams Administrator (of course global admin is also possible)
See also this link from docs.microsoft.com

What the script can do;
– Checks all teams if there are guest users
– finding only guest users
– Matching team Name, GroupID, Guestsettings, Guestusers
– Creating an html /csv file with the informations

NOTE: if you want to use the current Teams PowerShell Module you need to have PowerShell 5.1 See this link to install

The following screenshots show the output of the script

CSV file

html report

Scripting area

#installing module
Install-Module MicrosoftTeams -Verbose -Scope AllUsers -Force
#importing the teams module
Import-Module MicrosoftTeams -Verbose -Force
$creds = Get-Credential
Connect-MicrosoftTeams -Credential $creds -Verbose
#get all teams 
$teams = Get-Team
#create array for output 
$teamsarray =@()
#check every team found
foreach($team in $teams){
    #get group id 
    $grpid = ($team).GroupId
    #get guest users if exists
    $guestusers = Get-TeamUser -GroupId $grpid -Role Guest
    # check if there are some guest users
    if($guestusers){
    #getting teams parameters for display later
    $name = ($team).DisplayName
    $visibility = ($team).Visibility
    $guestupdate = ($team).AllowGuestCreateUpdateChannels
    $guestdelete = ($team).AllowGuestDeleteChannels
    $guestusername = ($guestusers).User
    #creating a new custom object to fit all information together
    $teamsguest = New-Object System.Object
    $teamsguest | Add-Member -type NoteProperty -name DisplayName -Value $name 
    $teamsguest | Add-Member -type NoteProperty -name HasGuestUsers -Value "TRUE" 
    $teamsguest | Add-Member -type NoteProperty -name Visibility -Value $visibility 
    $teamsguest | Add-Member -type NoteProperty -name AllowGuestCreateUpdateChannels -Value $guestupdate
    $teamsguest | Add-Member -type NoteProperty -name AllowGuestDeleteChannels -Value $guestdelete
    $teamsguest | Add-Member -type NoteProperty -name GroupID -Value $grpid
    $teamsguest | Add-Member -type NoteProperty -name GuestUser -Value (@($guestusername) -join " ")
    #adding every team to the array for displaying
    $teamsarray += $teamsguest
    }
    #if team has no guest users, nothing is written into array
    else{
        #only output in powershell console
        $name = ($team).DisplayName
        Write-Host "No guest users found in Team: $name " -ForegroundColor Yellow
        }
}
        $Header = @"
        <style>
        TABLE {border-width: 1px; border-style: solid; border-color: black; border-collapse: collapse;}
        TD {border-width: 1px; padding: 3px; border-style: solid; border-color: black;}
        </style>
"@
$teamsarray |Sort-Object DisplayName | ConvertTo-Html -Property DisplayName,Visibility,AllowGuestCreateUpdateChannels,AllowGuestDeleteChannels,GroupID,GuestUser  -Head $Header | Out-File -FilePath .\msteam-guests.html
Invoke-Expression ".\msteam-guests.html"
$teamsarray | Export-Csv -Path .\msteams-guest.csv -Encoding UTF8 -Delimiter ";"

If you found this article helpful let me know by clicking on “helpful”. Have fun.

Was this article helpful?
YesNo
0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Newest
Oldest Most Voted
Inline Feedbacks
View all comments