Configuring Teams to deploy minimized - mattnovitsch/M365 GitHub Wiki

Summary

I had a customer ask about configuring Teams to be deployed minimized. This can be done per user basis, but they were looking for doing it via global settings. PowerShell and Intune to the rescue! This article will walk you through deployment of the script I have found

Reference

Prerequisites

Steps:

  1. Navigate to Microsoft Endpoint Manager
  2. Navigate to Reports > Endpoint Analytics
  • Note: You can do this via scripts also but since we are trying to force this change in an organization having it run more than once is best handled in Endpoint Analytics image
  1. Click on Proactive Remediations and then Create script package image
  2. Provide your script package a name. I'm naming mine "Deploying Teams Minimized" image
  3. Upload the script that was download earlier as a prerequisite and make sure to change "Run this script using the logged-on credentials", this is important as the registry keys changed by the PowerShell are in HKeyCurrentUser. image
  4. Assign Tag accordingly image
  5. Assign to the correct group or all devices.
  • Note: If you click Daily you can modify the run time from daily, hourly, or once. image
  1. Click Create after you review the configuration. image

Script deep dive

This script currently allows you to change three settings in the json: Open as hidden, Open at Login, and Running on close. The notes in the script are pretty detailed so I won't go into much details on them. OpenasHidden is the value you would want to be True for it to open minimized. The script does close teams then makes the change and reopens it. If all goes well the first run will close teams and appear to be done but if you open your system tray you will see it there. Follow up runs will not have any impact on the user.

  • Note: if you run this more than once it will still close Teams and reopen it, so depending on when the script fires off it could impact user experience

#Open in the background $openAsHidden=$true #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 } }