Last active
June 6, 2020 09:28
-
-
Save thomyg/02eabc39ee2be2e06878e5351f3b2edf to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Small script that iterates through all Microsoft Teams teams | |
# and counts the usage of Teams apps using the Office365CLI | |
o365 login -t password -u "%USER_NAME" -p "%PASSWORD%" | |
$availableTeams = o365 teams team list -o json | ConvertFrom-Json | |
if($availableTeams.count -gt 15) | |
{ | |
$duration = [math]::Round(($availableTeams.count/60),1); | |
Write-Host "Start iterating through" $availableTeams.count "teams. This probably will take around" $duration" minutes to finish." | |
} | |
$appcounts = @{ } | |
foreach ($team in $availableTeams) { | |
$apps = o365 teams app list -i $team.id -a -o json | |
Write-Host "Counting apps in team: " $team.displayName " " $team.id | |
$appsJson = $apps | ConvertFrom-Json | |
$appsJson | foreach { | |
if ($appcounts.ContainsKey($_.teamsApp.displayName)) { | |
$appcounts[$_.teamsApp.displayName] = [Int32]$appcounts[$_.teamsApp.displayName] + 1 | |
} | |
else { | |
$appcounts.Add($_.teamsApp.displayName, [Int32]"1") | |
} | |
} | |
} | |
foreach ($h in $appcounts.GetEnumerator() | Sort-Object -Property value) { | |
Write-Output "$($h.Name): $($h.Value)" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment