Configuring Startup Settings in Microsoft Teams with Windows PowerShell

0
Share


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:APPDATAMicrosoftTeamsdesktop-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:APPDATAMicrosoftTeamsdesktop-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:APPDATAMicrosoftTeamsdesktop-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:APPDATAMicrosoftTeamsdesktop-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:APPDATAMicrosoftTeamsdesktop-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

The post Configuring Startup Settings in Microsoft Teams with Windows PowerShell appeared first on Scripting Blog.



Source link

Related Posts