Created
April 4, 2020 11:53
-
-
Save garrytrinder/e2d7bb648116cb43cfb8e1e8117f309e to your computer and use it in GitHub Desktop.
Install a Microsoft Teams application for all users in a tenant
This file contains hidden or 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
[CmdletBinding()] | |
param ( | |
[Parameter()] | |
[string] | |
$appName | |
) | |
$users = o365 aad user list --properties "id,displayName" -o json | ConvertFrom-Json | |
$app = o365 teams app list -o json | ConvertFrom-Json | Where-Object { $_.displayName -eq $AppName } | |
if ($null -ne $app) { | |
$token = o365 util accesstoken get -r "https://graph.microsoft.com" --new | |
$users | ForEach-Object { | |
$userName = $_.displayName | |
$options = @{ | |
Method = "Post" | |
Uri = "https://graph.microsoft.com/beta/users/$($_.id)/teamwork/installedApps" | |
ContentType = "application/json" | |
Body = @{ | |
"[email protected]" = "https://graph.microsoft.com/beta/appCatalogs/teamsApps/$($app.id)" | |
} | ConvertTo-Json | |
Headers = @{ | |
"Authorization" = "Bearer $token" | |
} | |
} | |
try { | |
Invoke-RestMethod @options | |
Write-Host "$appName succesfully installed for $userName" -ForegroundColor Green | |
} | |
catch { | |
Write-Host "There was an issue installing $appName for $userName" | |
Write-Host $_.Exception.Message | |
} | |
} | |
} | |
else { | |
Write-Error "$appName not found in tenant" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment