Disabling hardware acceleration in Teams on virtual desktops is a bit tricky since there’s currently no GPO setting for it. Despite the challenge, this is something that must be done in order to help keep your environment as lean as possible. Here’s a PowerShell script that will connect to the vCenter server, pull a list of VMs and then will cycle through every user profile on each VM to ensure that hardware acceleration is disabled in the users profile.
<# .SYNOPSIS Disables the hardware acceleration option in MS Teams .DESCRIPTION This script will connect to a desktop, access all profiles in C:\users and will look for the desktop-config.json file located in:C:\Users\<Username>\AppData\Roaming\Microsoft\Teams It will search the desktop-config.json file for "disableGpu" and either verify that the value is set to true or it will set the value to true and save the file .PARAMETER ParameterName .NOTES Name: Disable_Teams_HW_Acceleration.ps1Author: vNinja.techDateCreated: 2024-04-30DateUpdated: 2024-04-30Version: 1.0 .EXAMPLE .\FileName.ps1 -ParameterName Parameter Description ----------- #> # Import the modules if not already importedWrite-Host "Checking if the necessary modules are imported..."if (get-module VMware*) { Write-Host "VMware modules already imported. Skipping this step." -ForegroundColor DarkGreen Write-Host "`n"}else { Write-Host "Modules not detected. Importing the necessary VMware Modules. One moment..." -NoNewline Get-Module VMware* -ListAvailable | Import-Module -Verbose:$false Write-Host " modules imported!" -ForegroundColor DarkGreen Write-Host "`n"} # Check for creds, get creds if we don't have them yetWrite-Host "Checking if we have stored credentials yet..."if (!($creds)) { Write-Host "We need admin creds!" $creds = Get-Credential -Credential $null Write-Host "`n"}else { Write-Host "Admin credentials detected" -ForegroundColor DarkGreen Write-Host "`n"} # Command to connect to the vCSA$ConnectToVCSA = Connect-VIServer [vCSA here] -credential:get-credential -Verbose:$false Write-Host "Checking if we're already connected to the vCenter server..."# Connect to the vCenter server if we're not already connectedif (!($global:defaultviserver)) { Write-Host "No connection detected. Connecting to the vCSA now" Write-Host "`n" Try { $ConnectToVCSA } Catch { Write-Host "Failed to connect to the vCSA" -ForegroundColor DarkRed Write-Host "Error is $Error" }}else { Write-Host "Already connected to the vCenter server" -ForegroundColor DarkGreen Write-Host "`n"} # Check for creds, get creds if we don't have them yetWrite-Host "Checking if we have stored credentials yet..."if (!($creds)) { Write-Host "We need admin creds!" $creds = Get-Credential -Credential $null Write-Host "`n"}else { Write-Host "Admin credentials detected" -ForegroundColor DarkGreen Write-Host "`n"} # Create the variables # different ways to define the VMs#$VMList = "[VM name]"#$VMList = import-csv -path C:\path\to\file.csv$VMList = get-vm *VDI* $TextToFind = "`"disableGpu`":false"$TextToReplace = "`"disableGpu`":true" foreach ($VM in $VMList) { write-host VM name is $VM #$VMSession = New-PSSession -ComputerName $VM -Credential $Creds $UserProfiles = Get-ChildItem -Path \\$VM\C$\Users -Directory foreach ($UserProfile in $UserProfiles) { #write-host "Working on $VM and searching through $UserProfile" $StartingDir = \\$VM\C$\Users\ + $UserProfile + "\AppData\Roaming\Microsoft\Teams" $FileName = "desktop-config.json" $FullFilePath = $StartingDir + "\" + $FileName #write-host "Searching for $FullFilePath" if (Test-Path -Path $FullFilePath -PathType Leaf) { #Write-Host "Teams file located in $UserProfile directory on VM $VM." $content = Get-Content $FullFilePath if ($content -match $TextToFind) { write-host "Hardware acceleration is enabled for $UserProfile Teams. Disabling this now." $updatedContent = $content -replace $TextToFind, $TextToReplace Set-Content -Path $FullFilePath -Value $updatedContent } else { Write-Host "Hardware acceleration is already disabled for $UserProfile." } } }#>}

Leave a Reply