I’ve seen multiple Reddit posts, Microsoft posts and ‘User Voice’ posts requesting the ability to launch Microsoft Teams minimised in the system tray. The general consensus is that launching Teams in full screen mode is too invasive when users first log in to their desktop session.
Luckily in the latest version of Microsoft Teams, there is an option in Settings to ‘open application in the background’.
This is all well and good. But from a deployment perspective we can’t ask all users to manually check this box, and so we need to think of how we can automate this configuration.
Launch Microsoft Teams Minimised in System Tray
I’ve done some debugging and found that these configurations are stored in a JSON file located here: %APPDATA%\Microsoft\Teams\desktop-config.json
And the settings look like this:
Unfortunately at the time of writing, Microsoft haven’t provided an ADMX template to configure these settings via Group Policy. So we need to configure them via PowerShell instead.
Just a note before we continue, is that the organisation we’re currently working with have disabled Teams from automatically launching due to not wanting it to take over the desktop when it launches. Upon further investigation their deployment script hacks it out of the ‘Run’ registry key:
reg delete HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Run /v Teams /f
Because of this, we decided to create a login script (a note on running PowerShell login scripts) to configure the aforementioned settings and also launch Teams afterwards. Since Teams comes in multiple variants (per-user, per-machine x86 and per-machine x64) we’ve tried to cater for all versions.
Try {
#Open in the background
$openAsHidden=$false
#Open after login
$openAtLogin=$true
#Keep running in background when we 'close' teams
$runningOnClose=$true
$jsonFile = [System.IO.Path]::Combine($env:APPDATA, 'Microsoft', 'Teams', 'desktop-config.json')
if (Test-Path -Path $jsonFile) {
#Get Teams Configuration
$jsonContent =Get-Content -Path $jsonFile -Raw
#Convert file content from JSON format to PowerShell object
$jsonObject = ConvertFrom-Json -InputObject $jsonContent
#Update Object settings
if ([bool]($jsonObject.appPreferenceSettings -match "OpenAsHidden")) {
$jsonObject.appPreferenceSettings.OpenAsHidden=$openAsHidden
} else {
$jsonObject.appPreferenceSettings | Add-Member -Name OpenAsHidden -Value $openAsHidden -MemberType NoteProperty
}
if ([bool]($jsonObject.appPreferenceSettings -match "OpenAtLogin")) {
$jsonObject.appPreferenceSettings.OpenAtLogin=$openAtLogin
} else {
$jsonObject.appPreferenceSettings | Add-Member -Name OpenAtLogin -Value $openAtLogin -MemberType NoteProperty
}
if ([bool]($jsonObject.appPreferenceSettings -match "RunningOnClose")) {
$jsonObject.appPreferenceSettings.RunningOnClose=$runningOnClose
} else {
$jsonObject.appPreferenceSettings | Add-Member -Name RunningOnClose -Value $runningOnClose -MemberType NoteProperty
}
#Terminate Teams if it is running
$teamsProcess = Get-Process Teams -ErrorAction SilentlyContinue
If ($teamsProcess) {
#Close Teams Window
$teamsProcess.CloseMainWindow() | Out-Null
Sleep 5
#Close Teams
Stop-Process -Name "Teams" -Force -ErrorAction SilentlyContinue
}
#Update configuration
$jsonObject | ConvertTo-Json -Depth 5 | Set-Content -Path $jsonFile -Force
#Define Teams Update.exe paths
$userTeams = [System.IO.Path]::Combine("$env:LOCALAPPDATA", "Microsoft", "Teams", "current", "Teams.exe")
$machineTeamsX86 = [System.IO.Path]::Combine("$env:PROGRAMFILES (X86)", "Microsoft", "Teams", "current", "Teams.exe")
$machineTeamsX64 = [System.IO.Path]::Combine("$env:PROGRAMFILES", "Microsoft", "Teams", "current", "Teams.exe")
#Define arguments
$args = @("-process-start-args","""--system-initiated""")
#Launch Teams
if (Test-Path -Path $userTeams) {
Start-Process -FilePath $userTeams -ArgumentList $args
} elseif (Test-Path -Path $machineTeamsX86) {
Start-Process -FilePath $machineTeamsX86 -ArgumentList $args
} elseif (Test-Path -Path $machineTeamsX64) {
Start-Process -FilePath $machineTeamsX64 -ArgumentList $args
}
}
} catch {
#do something
#$_.Exception
}
Please note that at the time of writing, this is still in pre-production. It seems to work on the limited testing we have done. But I’ll gladly welcome feedback over in our community pages.