Adding language to rds environment based on the ts

  Kiến thức lập trình

I’m trying to assign users in rds environment keyboard languages based on the ts the Assigned for example if user assign to ts “tsA” spanish will be added to the keyboard if assigned to other ts spanish will not be assigned.
Languages are assigned by user but not by computer, and i can’t create a gpo to specific users ou because all users have access to each collection, and i need some how to run on all users and based the ts they enter language be added.

Right now the idea I’m thinking of is creating a gpo that will run a powershell script that will add and remove based on the hostname

# Get the name of the VM
$vmName = (Get-WmiObject -Class Win32_ComputerSystem).Name

# Language to add/remove
$lang = "es-ES"

# Get the current language list
$languageList = Get-WinUserLanguageList

# Check if the VM name indicates it's a Spanish environment
if ($vmName -like "*tsA*") {
    # Check if Spanish keyboard layout is already installed
    if (-not ($languageList.LanguageTag -contains $lang)) {
        # Install Spanish keyboard layout
        $languageList.Add($lang)
        Set-WinUserLanguageList $languageList -Force

        Write-Output "Spanish keyboard layout installed and set as default."
    } else {
        Write-Output "Spanish keyboard layout is already installed."
    }
} else {
    # Check if Spanish keyboard layout is installed and remove it
    if ($languageList.LanguageTag -contains $lang) {
        $languageList = $languageList | Where-Object { $_.LanguageTag -ne $lang }
        Set-WinUserLanguageList $languageList -Force

        Write-Output "Spanish keyboard layout removed."
    } else {
        Write-Output "This VM does not require the Spanish keyboard layout."
    }
}

What basically have his 2 questions.
1.is their a better way to achieve what I’m trying to get?
2.the gpo not adding the language upon logon and I don’t believe it the script any other things I should check?
Thanks

LEAVE A COMMENT