public/Get/Get-CurrentISETheme.ps1
function Get-CurrentISETheme { <# .SYNOPSIS Gets the currently applied PowerShell ISE theme as a structured collection of color objects. .DESCRIPTION The Get-CurrentISETheme function returns the active ISE theme, including base UI colors, token classification colors, XML-specific token colors, and console-specific token colors. All color values are converted to ARGB objects for portability and consistency. In addition to colors, the function includes font metadata such as FontFamily and FontSize in a separate "Other" classification. .EXAMPLE PS C:\> $theme = Get-CurrentISETheme Retrieves the current theme and stores it in the variable $theme for export or modification. .NOTES Author: Jeff Pollock GitHub: https://github.com/phriendx/ISEColorTheme.cmdlets Website: https://pxlabs.info #> [CmdletBinding()] param() $theme = @() # Helper: Converts property to ARGB color object function New-ColorObject { param ( [string]$Class, [string]$Attribute, [string]$Hex ) $argb = Convert-HexToARGB $Hex [pscustomobject]@{ Class = $Class Attribute = $Attribute A = $argb.A R = $argb.R G = $argb.G B = $argb.B Hex = $Hex } } # Base Theme Colors $baseProperties = @( 'ErrorForegroundColor', 'ErrorBackgroundColor', 'WarningForegroundColor', 'WarningBackgroundColor', 'VerboseForegroundColor', 'VerboseBackgroundColor', 'DebugForegroundColor', 'DebugBackgroundColor', 'ConsolePaneBackgroundColor', 'ConsolePaneTextBackgroundColor', 'ConsolePaneForegroundColor', 'ScriptPaneBackgroundColor', 'ScriptPaneForegroundColor' ) foreach ($prop in $baseProperties) { $hex = $psISE.Options.$prop $theme += New-ColorObject -Class 'Base' -Attribute $prop -Hex $hex } # TokenColors foreach ($token in $psISE.Options.TokenColors.GetEnumerator()) { $theme += New-ColorObject -Class 'TokenColors' -Attribute $token.Key -Hex $token.Value } # ConsoleTokenColors foreach ($token in $psISE.Options.ConsoleTokenColors.GetEnumerator()) { $theme += New-ColorObject -Class 'ConsoleTokenColors' -Attribute $token.Key -Hex $token.Value } # XmlTokenColors foreach ($token in $psISE.Options.XmlTokenColors.GetEnumerator()) { $theme += New-ColorObject -Class 'XmlTokenColors' -Attribute $token.Key -Hex $token.Value } # Font Metadata $theme += [pscustomobject]@{ Class = 'Other' Attribute = 'Other' A = 0; R = 0; G = 0; B = 0 FontFamily = $psISE.Options.FontName FontSize = $psISE.Options.FontSize } return $theme } |