Fernando Klurfan1709153904 Posted October 14, 2020 Share Posted October 14, 2020 The objective of this post is to allow the community to share powershell scripts for Teams that can benefit other Admins. Feel free to share yours! .\Teams_enable_gpu.ps1 -disable [CmdletBinding()] Param( [switch] $disable ) $DebugPreference = 'SilentlyContinue'; if ($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent) { $DebugPreference = 'Continue' } $jsonfile = "{0}\Microsoft\Teams\desktop-config.json" -f $env:AppData Write-Debug ("disable={0}" -f [bool]$disable) Write-Debug ("jsonfile={0}" -f $jsonfile) if (Test-Path $jsonfile) { Write-Debug ("File exists.") $json = Get-Content $jsonfile | ConvertFrom-Json Write-Debug ("disableGpu={0}" -f [bool]$json.appPreferenceSettings.disableGpu) if ([bool]$json.appPreferenceSettings.disableGpu -ne [bool]$disable) { $json.appPreferenceSettings.disableGpu = [bool]$disable $json | ConvertTo-Json | Out-File $jsonfile -Encoding ASCII Write-Debug ("File modified.") } } Link to comment
0 Ray Davis1709159190 Posted October 15, 2020 Share Posted October 15, 2020 I run a script now to update the Json file, It will update the JSon file, Then Teams sets it back on startup. We set it with WEM. You can see it chance the GPU options. Then Teams sets it back. I am running this now $filepath = "$env:APPDATA\microsoft\teams\desktop-config.json" $existing = Get-Content $filepath -raw|ConvertFrom-Json $existing.appPreferenceSettings.disableGpu = 'true' $existing.appPreferenceSettings.openAtLogin = 'false' $existing |ConvertTo-Json|Set-Content $filepath How have you verified, that teams isnt setting this back? We had many discussion on slack, and Teams isnt honoring the json file changes most times. Link to comment
0 Justin Miller1709155625 Posted October 15, 2020 Share Posted October 15, 2020 4 hours ago, Ray Davis1709159190 said: I run a script now to update the Json file, It will update the JSon file, Then Teams sets it back on startup. We set it with WEM. You can see it chance the GPU options. Then Teams sets it back. I am running this now $filepath = "$env:APPDATA\microsoft\teams\desktop-config.json" $existing = Get-Content $filepath -raw|ConvertFrom-Json $existing.appPreferenceSettings.disableGpu = 'true' $existing.appPreferenceSettings.openAtLogin = 'false' $existing |ConvertTo-Json|Set-Content $filepath How have you verified, that teams isnt setting this back? We had many discussion on slack, and Teams isnt honoring the json file changes most times. Teams must be closed when making these setting changes in my experience Link to comment
0 Ray Davis1709159190 Posted October 16, 2020 Share Posted October 16, 2020 yea we use this in WEM, Teams isn't opened at the time. We kill it at startup, and I have a WEM external Task that will make sure it doesn't start up even if the user tries to set it., But I will try your script, thanks for sharing and helping. Link to comment
0 Stefan Gloeckle Posted October 18, 2020 Share Posted October 18, 2020 On 10/15/2020 at 2:18 PM, Ray Davis1709159190 said: I run a script now to update the Json file, It will update the JSon file, Then Teams sets it back on startup. We set it with WEM. You can see it chance the GPU options. Then Teams sets it back. I am running this now $filepath = "$env:APPDATA\microsoft\teams\desktop-config.json" $existing = Get-Content $filepath -raw|ConvertFrom-Json $existing.appPreferenceSettings.disableGpu = 'true' $existing.appPreferenceSettings.openAtLogin = 'false' $existing |ConvertTo-Json|Set-Content $filepath How have you verified, that teams isnt setting this back? We had many discussion on slack, and Teams isnt honoring the json file changes most times. Hi davisra1983 nearly works for me but it seems Teams does not correctly recognize the values set in " " Your changes the value from e.g. = true to = "true" Is there any way to prevent the " " ? thanks, Stefan p.s.: Teams will still autostart on logon and I have no idea why Link to comment
0 Stefan Gloeckle Posted October 18, 2020 Share Posted October 18, 2020 Ok I found the answer on my own Change script content to $filepath = "$env:APPDATA\microsoft\teams\desktop-config.json" $existing = Get-Content $filepath -raw|ConvertFrom-Json $existing.appPreferenceSettings.disableGpu = $true $existing.appPreferenceSettings.openAtLogin = $false $existing |ConvertTo-Json|Set-Content $filepath that does work fine cheers Link to comment
0 Troy Sackett Posted October 19, 2020 Share Posted October 19, 2020 This modified version worked for me: [CmdletBinding()] Param( [switch] $disable ) $DebugPreference = 'SilentlyContinue'; if ($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent) { $DebugPreference = 'Continue' } $jsonfile = $env:AppData+"\Microsoft\Teams\desktop-config.json" Write-Debug ("disable={0}" -f [bool]$disable) Write-Debug ("jsonfile={0}" -f $jsonfile) if (get-process -Name Teams -ErrorAction SilentlyContinue) { Write-Host -ForegroundColor Red "Teams cannot be in memory. Please quit Teams and try again." Exit } if (Test-Path $jsonfile) { Write-Debug ("File exists.") $json = Get-Content $jsonfile | ConvertFrom-Json Write-Debug ("disableGpu={0}" -f [bool]$json.appPreferenceSettings.disableGpu) if ($json.appPreferenceSettings.disableGpu -eq $False) { $json.appPreferenceSettings.disableGpu = $True $json | ConvertTo-Json | Out-File $jsonfile -Encoding ASCII Write-Debug ("File modified.") } } Link to comment
0 Robert Berggren1709162216 Posted October 27, 2020 Share Posted October 27, 2020 I am worthless on Powershell but I do like this: Delete from RUN key in local machine of course. In WEM create the same key but in user hive and apply only to users needing the program and "Run Once" checked. This is to get the inital setup started only and the json file created. Then on subsequent logins this script will always run and if necessary do the changes again and then start Teams. Since I cannot make PS scripts from scratch this is a mix of others work and my own ideas. $CheckFile = Test-Path "$env:AppData\Microsoft\Teams\desktop-config.json" if ($CheckFile -eq $False){ Does exit } Remove-ItemProperty -Path "HKCU:\software\Microsoft\Windows\CurrentVersion\Run" -Name "Teams" Stop-Process -Name Teams $SourceDesktopConfigFile = "$env:AppData\Microsoft\Teams\desktop-config.json" $Teams = (Get-Content -Path $SourceDesktopConfigFile | ConvertFrom-Json) Get-Content -Path $SourceDesktopConfigFile | ConvertFrom-Json #Set Desktop Teams Configuration $Teams.appPreferenceSettings.openAsHidden = $true #$Teams.appPreferenceSettings.runningOnClose = $true $Teams.appPreferenceSettings.disableGpu = $true #$Teams.appPreferenceSettings.registerAsIMProvider = $true #Overwrite $Teams | ConvertTo-Json -Compress | Set-Content -Path $SourceDesktopConfigFile -Force Write-Verbose $Teams.appPreferenceSettings.openAsHidden #Write-Verbose $Teams.appPreferenceSettings.runningOnClose Write-Verbose $Teams.appPreferenceSettings.disableGpu #Write-Verbose $Teams.appPreferenceSettings.registerAsIMProvider Start-Process "C:\Program Files (x86)\Microsoft\Teams\current\Teams.exe" "--process-start-args --system-initiated" Link to comment
0 Jesse Bradford Posted February 11, 2021 Share Posted February 11, 2021 [CmdletBinding()] Param( # Parameter help description [Parameter(Mandatory=$false)] [String] $jsonfile = $env:AppData+"\Microsoft\Teams\desktop-config.json", # Parameter help description [Parameter(Mandatory=$false)] [String] $User = $env:USERDOMAIN+'\'+$env:USERNAME ) Write-Verbose ($jsonfile) Write-Verbose ($User) if (Test-Path $jsonfile) { $json = Get-Content $jsonfile | ConvertFrom-Json Write-Verbose ($json.appPreferenceSettings) if ( ([bool]$json.appPreferenceSettings.disableGpu -eq $False) -or ([bool]$json.appPreferenceSettings.enableMediaLoggingPreferenceKey -eq $True) ) { Get-Process -Name 'Teams' -IncludeUserName -ErrorAction SilentlyContinue | Where-Object UserName -eq $User | Stop-Process -Force $json.appPreferenceSettings.disableGpu = $True $json.appPreferenceSettings.enableMediaLoggingPreferenceKey = $False $json | ConvertTo-Json | Out-File $jsonfile -Encoding ASCII Write-Verbose ("File has been modified.") & "$env:LOCALAPPDATA\Microsoft\Teams\Update.exe" --processStart "Teams.exe" } else { Write-Verbose ("Nothing needs to be done") } } else { Write-Error ("file does not exist: {0}", $jsonfile) } Alternative version with Verbose instead of Debug. Also, an example of implementing multiple value changes at once and working around the user Teams process (run in user context), and only in the case that a change is needed. Thanks to y'all's examples and my co-worker's code review and refinements. Link to comment
0 Jesse Bradford Posted May 31, 2022 Share Posted May 31, 2022 https://github.com/anothervictim/TeamsUserPreference Here's my initial commit on some PowerShell functions, so others can benefit and fork. These functions are fully functional for any Teams User PreferenceSetting, known or unknown. Will update the autofill values as I become aware of them. Link to comment
Question
Fernando Klurfan1709153904
The objective of this post is to allow the community to share powershell scripts for Teams that can benefit other Admins.
Feel free to share yours!
.\Teams_enable_gpu.ps1 -disable
[CmdletBinding()]
Param(
[switch] $disable
)
$DebugPreference = 'SilentlyContinue';
if ($PSCmdlet.MyInvocation.BoundParameters["Debug"].IsPresent) { $DebugPreference = 'Continue' }
$jsonfile = "{0}\Microsoft\Teams\desktop-config.json" -f $env:AppData
Write-Debug ("disable={0}" -f [bool]$disable)
Write-Debug ("jsonfile={0}" -f $jsonfile)
if (Test-Path $jsonfile) {
Write-Debug ("File exists.")
$json = Get-Content $jsonfile | ConvertFrom-Json
Write-Debug ("disableGpu={0}" -f [bool]$json.appPreferenceSettings.disableGpu)
if ([bool]$json.appPreferenceSettings.disableGpu -ne [bool]$disable) {
$json.appPreferenceSettings.disableGpu = [bool]$disable
$json | ConvertTo-Json | Out-File $jsonfile -Encoding ASCII
Write-Debug ("File modified.")
}
}
Link to comment
9 answers to this question
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now