profiles.objects array within the settings.json configuration file. This approach allows you to programmatically update specific profile settings, such as the fontFace property, without manually editing the JSON structure or restarting the application immediately.
Understanding Windows Terminal Configuration
Windows Terminal stores all its user preferences in a single JSON file located at%LOCALAPPDATA%\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json. While you can edit this file directly with any text editor, using PowerShell provides a structured way to read, modify, and write these changes safely. The terminal uses a hierarchical object model where global settings sit alongside individual profiles for each shell like PowerShell, Command Prompt, or WSL distributions.
To manipulate these settings via script, you must first load the existing configuration into a PowerShell object. This ensures that when you save the changes, you do not accidentally delete other important configurations or break the JSON syntax. It is crucial to work with the loaded object rather than raw string manipulation to maintain data integrity.
Locating and Modifying the Profile
The first step involves reading thesettings.json file and converting it into a PowerShell custom object. Once loaded, you need to identify the specific profile you wish to modify. Each profile has a unique guid which serves as its identifier. You can list all available profiles by accessing the profiles.objects collection.
Here is how you can retrieve the configuration and target a specific profile:
$configPath = "$env:LOCALAPPDATA\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\LocalState\settings.json"
$settings = Get-Content $configPath | ConvertFrom-Json
# Find the profile by name or guid
$targetProfile = $settings.profiles.objects | Where-Object { $_.name -eq "PowerShell" }
if ($targetProfile) {
# Set the new font face
$targetProfile.fontFace = "Cascadia Code"
# Optionally adjust font size
$targetProfile.fontSize = 14
# Save the modified settings back to the file
$settings | ConvertTo-Json -Depth 100 | Set-Content $configPath
} else {
Write-Error "Profile 'PowerShell' not found."
}
In this script, we use ConvertFrom-Json to parse the file. We then filter the profiles.objects array to find the entry matching our desired name. Note that if you have multiple profiles with similar names, you might want to match against the guid instead for precision. After updating the fontFace property, we convert the entire object back to JSON and overwrite the original file. The -Depth 100 parameter is critical because Windows Terminal configurations are deeply nested; without it, the conversion might truncate complex objects.
Applying Changes Without Restart
While writing tosettings.json usually triggers an automatic refresh in Windows Terminal, sometimes the UI does not update instantly. If you notice the font has not changed after running the script, you may need to restart the terminal window or the entire application. However, for most users, simply saving the file is sufficient because the terminal monitors the configuration file for changes.
It is also worth noting that not all fonts support all character sets. If you switch to a custom font, ensure it supports the glyphs required by your shell environment, especially if you use special characters or emojis. Fonts like Cascadia Code, Fira Code, or JetBrains Mono are popular choices among developers for their ligatures and clarity.
For those interested in automating other aspects of their terminal environment, you might find it useful to explore how to open PowerShell.exe using Windows Terminal Preview instead of regular Windows Terminal. This can complement your font customization by allowing access to newer features before they reach the stable release channel.
Verifying the Font Change
After executing the script, open a new tab in Windows Terminal to verify the changes. The new font should be applied immediately to the selected profile. If the font appears incorrectly or defaults back to the system font, check the following:- Ensure the font name matches exactly what is installed on your system.
- Verify that the JSON syntax remains valid after modification.
- Check that no other overriding settings exist in the
defaultssection of the profiles.
$currentFont = ($settings.profiles.objects | Where-Object { $_.name -eq "PowerShell" }).fontFace
Write-Host "Current Font: $currentFont"
This diagnostic step helps isolate issues related to the script execution versus the terminal's rendering engine.
Managing Multiple Profiles
If you manage several shells, you may want to apply the same font across all profiles or differentiate them based on the environment. You can iterate through theprofiles.objects array and apply the font setting to each item individually. This is particularly useful for maintaining a consistent look and feel across different development environments.
Additionally, you can create new profiles dynamically using PowerShell if you need to add custom command-line tools. This flexibility makes Windows Terminal a powerful hub for developers who rely on diverse toolchains.
For more advanced configuration management, understanding how to programmatically change the Windows 11 color scheme can help you create a cohesive visual theme between your operating system and your terminal sessions. Consistent theming reduces eye strain and improves workflow efficiency.
Frequently Asked Questions
Does changing the font require administrative privileges?
No, modifying the settings.json file only requires user-level permissions since it is stored in your local AppData folder. You do not need to run PowerShell as an administrator to change font settings for your own user account.
What happens if I specify a font that is not installed?
Windows Terminal will fall back to the default font specified in the profile or the global defaults. It will not throw an error but will silently revert to a readable fallback to ensure the terminal remains usable.
Can I change the font size programmatically as well?
Yes, you can modify the fontSize property in the same manner as fontFace. Simply assign an integer value representing the point size to the fontSize key in your PowerShell script before saving the settings.
How do I reset the font to the default setting?
To reset the font, you can either delete the fontFace property from the profile object in the JSON file or set it to an empty string. Windows Terminal will then automatically revert to its built-in default font for that profile.
Will these changes affect other users on the same computer?
No, the settings.json file is user-specific and located in your personal profile directory. Other users on the same machine will have their own separate configuration files and will not see your font changes unless they explicitly import your settings.