public/Set/Set-ISEThemeColors.ps1

function Set-ISEThemeColors {
    <#
    .SYNOPSIS
        Applies color values (and optionally font settings) to the current ISE session.
 
    .DESCRIPTION
        The Set-ISEThemeColors function receives a theme object—typically produced by Get-ISETheme or
        Set-ISEColorAdjustment—and updates the PowerShell ISE's color configuration accordingly. It applies
        TokenColors, ConsoleTokenColors, XmlTokenColors, and base ISE UI colors. If the -SetFont switch is
        specified and font metadata is present, it also updates the FontFamily and FontSize.
 
    .PARAMETER ThemeData
        An array of theme elements that define the color mappings for the ISE environment.
 
    .PARAMETER SetFont
        If specified, applies FontFamily and FontSize from the theme data when available.
 
    .EXAMPLE
        Set-ISEThemeColors -ThemeData $theme
 
        Applies all color elements from the supplied theme data to the current ISE session, excluding font changes.
 
    .EXAMPLE
        Set-ISEThemeColors -ThemeData $theme -SetFont
 
        Applies the theme colors and updates the ISE editor font and size as defined in the theme object.
 
    .NOTES
        Author: Jeff Pollock
        GitHub: https://github.com/phriendx/ISEColorTheme.cmdlets
        Website: https://pxlabs.info
    #>


    [CmdletBinding()]
    param (
        [Parameter(Mandatory)]
        [object[]]$ThemeData,

        [switch]$SetFont
    )

    foreach ($item in $ThemeData) {
        switch ($item.Class) {
            { $_ -eq 'TokenColors' } {
                $psISE.Options.TokenColors[$item.Attribute] = $item.Hex
                continue
            }
            { $_ -eq 'ConsoleTokenColors' } {
                $psISE.Options.ConsoleTokenColors[$item.Attribute] = $item.Hex
                continue
            }
            { $_ -like '*XmlTokenColors*' } {
                if ($item.Attribute.Length -gt 2) {
                    $psISE.Options.XmlTokenColors[$item.Attribute] = $item.Hex
                }
                continue
            }
            { $_ -like 'Base*' } {
                switch -Wildcard ($item.Attribute) {
                    '*ErrorForegroundColor'   { $psISE.Options.ErrorForegroundColor = $item.Hex }
                    '*ErrorBackgroundColor'   { $psISE.Options.ErrorBackgroundColor = $item.Hex }
                    '*WarningForegroundColor' { $psISE.Options.WarningForegroundColor = $item.Hex }
                    '*WarningBackgroundColor' { $psISE.Options.WarningBackgroundColor = $item.Hex }
                    '*VerboseForegroundColor' { $psISE.Options.VerboseForegroundColor = $item.Hex }
                    '*VerboseBackgroundColor' { $psISE.Options.VerboseBackgroundColor = $item.Hex }
                    '*DebugForegroundColor'   { $psISE.Options.DebugForegroundColor = $item.Hex }
                    '*DebugBackgroundColor'   { $psISE.Options.DebugBackgroundColor = $item.Hex }
                    '*ConsolePaneBackgroundColor' { $psISE.Options.ConsolePaneBackgroundColor = $item.Hex }
                    '*ConsolePaneForegroundColor' { $psISE.Options.ConsolePaneForegroundColor = $item.Hex }
                    '*ConsolePaneTextBackgroundColor' { $psISE.Options.ConsolePaneTextBackgroundColor = $item.Hex }
                    '*ScriptPaneBackgroundColor' { $psISE.Options.ScriptPaneBackgroundColor = $item.Hex }
                    '*ScriptPaneForegroundColor' { $psISE.Options.ScriptPaneForegroundColor = $item.Hex }
                }
                continue
            }
            'Other' {
                if ($SetFont -and $item.PSObject.Properties.Name -contains 'FontFamily') {
                    $psISE.Options.FontName = $item.FontFamily
                    $psISE.Options.FontSize = $item.FontSize
                }
            }
        }
    }
}