Skip to content

Instantly share code, notes, and snippets.

@jesseloudon
Last active June 22, 2023 01:21
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save jesseloudon/e723b5f81b52daed41caba5c572566f5 to your computer and use it in GitHub Desktop.
Example #1 - PowerShell script to configure Microsoft Teams desktop settings. Useful to run via GPO targeting AD users.
param(
# Define parameters and values
[string]$newWebLanguage="en-au",
[string]$desktopConfigFile=$env:userprofile\\AppData\Roaming\Microsoft\Teams\desktop-config.json,
[string]$cookieFile="$env:userprofile\\AppData\Roaming\Microsoft\teams\Cookies",
[string]$registryPath="HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall",
[string]$registryDisplayName="Microsoft Teams",
[string]$processName="Teams"
)
#Check if Teams is installed
$registryPathCheck = Get-ChildItem -Path $registryPath -Recurse | Get-ItemProperty | Where-Object {$_.DisplayName -eq $registryDisplayName } -ErrorAction SilentlyContinue
#Check if Teams process is running
$processCheck = Get-Process $processName -ErrorAction SilentlyContinue
#Read the Teams desktop config file and convert from JSON
$config = (Get-Content -Path $desktopConfigFile | ConvertFrom-Json -ErrorAction SilentlyContinue)
#Check if required parameter value is already set within Teams desktop config file
$configCheck = $config | where {$_.currentWebLanguage -ne $newWebLanguage} -ErrorAction SilentlyContinue
#Check if Teams cookie file exists
$cookieFileCheck = Get-Item -path $cookieFile -ErrorAction SilentlyContinue
#1-If Teams is installed ($registryPathCheck not null)
#2-If Teams desktop config settings current value doesn't match parameter value ($configCheck not null)
#3-If Teams process is running ($processCheck not null)
#4-Then terminate the Teams process and wait 5 seconds
if ($registryPathCheck -and $configCheck -and $processCheck)
{
Get-Process $processName | Stop-Process -Force
Start-Sleep 5
}
#Check if Teams process is stopped
$processCheckFinal = Get-Process $processName -ErrorAction SilentlyContinue
#1-If Teams is installed ($registryPathCheck not null)
#2-If Teams desktop config settings current value doesn't match parameter value ($configCheck not null)
#3-Then update Teams desktop config file with new parameter value
if ($registryPathCheck -and $configCheck)
{
$config.currentWebLanguage=$newWebLanguage
$config | ConvertTo-Json -Compress | Set-Content -Path $desktopConfigFile -Force
#1-If Teams process is stopped ($processCheckFinal is null)
#2-If Teams cookie file exists ($cookieFileCheck not null)
#3-Then delete cookies file
if (!$processCheckFinal -and $cookieFileCheck)
{
Remove-Item -path $cookieFile -Force
}
}
@jesseloudon
Copy link
Author

@Kris3D
Copy link

Kris3D commented Apr 20, 2023

Hi, I am looking for a way to set the Teams user setting for notifications. Specifically the Chat notification setting.
I can't find them in de desktop-config.json nor the settings.json file. Any ideas?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment