Configuring Startup Settings in Microsoft Teams with Windows PowerShell

Doctor Scripto

Summary: Using the ConvertFrom-JSON and ConvertTo-JSON Cmdlets to edit a configuration file

Q: Hey, Doctor Scripto!

I need to be able to change the Startup settings in Teams (like the Auto launch feature). I can change it in the Interface, but I need to be able to edit across multiple systems. Could you lend me a hand?

—RL

A: Hello RL,

A very excellent question. For which it produced a most interesting solution when I asked Sean Kearney one of our Microsoft PFE’s to look at it. Take it away Sean!

Let’s begin by examining the settings we are trying to change. They can be accessed under the “Settings” in Teams

I saw the settings in questions but there didn’t appear to be a Group Policy which managed them.   There was a Policy that could be found here to prevent the initial startup that could be found here.   In addition, if so desired you could edit the XML file for Office Click to run to exclude the installation of Teams if so desired.

But if Teams was deployed and initially an Office wanted to delay use (*after say, until staff were trained*) it would still launch at login in some cases.

Since I couldn’t find a way online to do it so I decided to investigate. The first question which needed to be answered was “Where are the settings stored?”

To find that answer I pulled out the ever trustworthy tool from Sysinternals called “Procmon” which allows you to see what files and registry entries a process is accessing.

If you are curious on how to use this tool there is an excellent link from Christopher Haun on MSDN as well as a cool video from Scott Hanselman. In addition there are books written by Mark Russinovich and Aaron Margosis to show you all the ins and outs of this great suite of tools.

With a little bit of work I found a file which seemed to be written to when I checked and cleared the respective boxes. It was located under the following folder

$ENV:APPDATA\Microsoft\Teams\desktop-config.json

Since it was a JSON formatted file, I was able to read it and Convert it to a standard PowerShell object using this piece of PowerShell

# Read File into memory and store in $FileContent Object
$FileContent=Get-Content -path "$ENV:APPDATA\Microsoft\Teams\desktop-config.json"
# Convert Content from JSON format into a PowerShell Object
$JSONObject=ConvertFrom-Json -InputObject $FileContent

Once I had this object I could examine the contents (and did of course!)

I could see several settings, but one appeared to contain the four I was looking for, “appPreferenceSettings”

I examined one of the values that I was interested in. I needed to know type of an object it contained, in this case the ‘openAtLogin’ one. For this we can leverage the gettype() method which will show us the Type of object it is.

Knowing this was a Boolean Object, if I wanted to clear the box I needed to set it from $True (checked off) to $False (Cleared)

I updated the value in the following fashion.

$JSONObject.appPreferenceSettings.openAtLogin=$false

Now to test this I needed to do three things.

  1. Stop the Teams application
  2. Update the Settings file
  3. Restart the Teams application (and view the settings to see if they had updated)

# Stop Teams Process

Get-Process Teams | Stop-Process -force

$NewFileContent=$JSONObject | Convertto-JSON

# Update Teams Configuration file

$NewFileContent | Set-Content -path “$ENV:APPDATA\Microsoft\Teams\desktop-config.json”

I launched the Teams process and examined the settings which confirmed it was updated properly! I actually did a little dance on that one when I saw it work. (No really I did, and Mrs. EnergizedTech looked at me funny when it happened 😉 )

The process then was clearly simple.

  • Read JSON file configuration
  • Convert to PowerShell object
  • Edit Settings in Object
  • Terminate Teams Process
  • Update Settings

Here it was written as a Parameterized Script

param(
# Teams open in the background Hidden $true or $false
[boolean]$OpenAsHidden=$False,
# Teams open automatically at user login $true or $false
[boolean]$OpenAtLogin=$False,
# Close Teams App fully instead of running on Taskbar $true or $false
[boolean]$RunningOnClose=$False
)
# Get Teams Configuration
$FileContent=Get-Content -Path "$ENV:APPDATA\Microsoft\Teams\desktop-config.json"
# Convert file content from JSON format to PowerShell object
$JSONObject=ConvertFrom-Json -InputObject $FileContent
# Update Object settings
$JSONObject.appPreferenceSettings.OpenAsHidden=$OpenAsHidden
$JSONObject.appPreferenceSettings.OpenAtLogin=$OpenAtLogin
$JSONObject.appPreferenceSettings.$RunningOnClose=$RunningOnClose
# Terminate Teams Process
Get-Process Teams | Stop-Process -Force
# Convert Object back to JSON format
$NewFileContent=$JSONObject | ConvertTo-Json
# Update configuration in file
$NewFileContent | Set-Content -Path "$ENV:APPDATA\Microsoft\Teams\desktop-config.json"

 

Now with this script it was possible to update the settings in an easier fashion whether by Group Policy, Login script or any one of many other options.

I hope you found this of use in one of three ways

  1. This solved a problem for you in updating settings
  2. Learning how to edit JSON files with PowerShell
  3. Discovering the cool tools like ProcMon Sysinternals offers

Thanks Sean for sharing that with us! So RL that is all there is to editing the Teams configuration with PowerShell.

I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at scripter@microsoft.com, or post your questions on the Official Scripting Forum. See you tomorrow. Until then, peace.

Your good friend, Doctor Scripto

PowerShell, Doctor Scripto, Sean Kearney, JSON, Teams, Sysinternals, Procmon

2 comments

Discussion is closed. Login to edit/delete existing comments.

  • a a 0

    Ok so this kind of works. I was able to set 2 out of three properties, but i think your code at line 16 is not correct. Did you mean to double up the $RunningOnClose there? Because the command does not work with that there. I think the first instance has an extra dollar sign. If i remove the first dollar sign which i believe erroneous, it works and sets the properties. You should correct the typo.

    Also to note for anyone testing, on subsequent runs of the PS1 script, you need to launch teams in between runs. The script makes the file be full of whitespace, but when you run teams it removes all the whitespace and shifts everything together. The script does not work if that whitespace is there, giving errors about not finding the properties. But if you run teams, kill it, and then run the script again, it works as expected. I initially thought it was broken before i re ran teams and it squished it all back together again.

    thanks for the script, it helps alot. Would prefer a GPO to do this because it is windows after all. Flat preference files is more of a unix thing.

  • Paul Jones 0

    This is awesome. Did anyone figure out how to flip on / off the setting ‘Register Teams as the chat app for Office’? This one is causing us a massive headache and we need to turn it off. Changing the json file has not affect.

Feedback usabilla icon