Summary: Join Microsoft Scripting Guy Ed Wilson as he takes you on a guided tour of the Windows PowerShell ISE color objects. Microsoft Scripting Guy Ed Wilson here. It is a beautiful sunny afternoon. I have decided to embrace the sunshine and accept the humidity that seems to be irrevocably joined with it. I have Deep Purple cranked up on my Zune HD, a great soundtrack for playing around with Windows PowerShell. I have a glass of Pelegrino (a habit I picked up during my many trips to Italy) and a fresh Lamington I picked up at an Australian Bakery I found on the Internet. I got addicted to Lamingtons from the first bite. I was working in Brisbane, Australia, teaching a VBScript workshop I had developed from the Microsoft Press VBScript Self-Paced Learning Edition book I wrote. My bride was joining me for the second week, so I was waiting at the Brisbane International Airport when I happened to look at the status board for the flight from Los Angeles. Because it was delayed for a couple of hours, I headed over to the little café they have and innocently bought a Lamington and a cup of English Breakfast tea. That was all it took. From then on, my life has been one continual search for the perfect Lamington and a quiet place in which to write scripts. Deep Purple seems to be just the right type of quiet and it pairs perfectly with a fresh Lamington. Anyway, I have finally found time to address a project I have wanted to examine for some time (having been restricted from my woodworking shop due to a foot injury and consequently growing tired of reading Shakespeare). The project I want to undertake today is to look at modifying the Windows PowerShell ISE. Inside the Windows PowerShell ISE, an automatic variable $psISE is created to represent the ISE. You can use Windows PowerShell cmdlets such as Format-List and Get-Member to explore the objects that are returned by the $psISE variable. This is shown here:
PS C:Usersedwils> $psISE | Format-List *
CurrentPowerShellTab : Microsoft.PowerShell.Host.ISE.PowerShellTab
CurrentFile : Microsoft.PowerShell.Host.ISE.ISEFile
Options : Microsoft.PowerShell.Host.ISE.ISEOptions
PowerShellTabs : {PowerShell 1}
Each of the properties exposed by $psISE returns an object, and that means they are all ripe for exploration. In fact, the $psISE itself is an object, as revealed by the Get-Member cmdlet output shown here:
PS C:Usersedwils> $psISE | Get-Member
TypeName: Microsoft.PowerShell.Host.ISE.ObjectModelRoot
Name MemberType Definition
—- ———- ———-
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
ToString Method string ToString()
CurrentFile Property Microsoft.PowerShell.Host.ISE.ISEFile CurrentFile {get;}
CurrentPowerShellTab Property Microsoft.PowerShell.Host.ISE.PowerShellTab CurrentPowerShellTab {get;}
Options Property Microsoft.PowerShell.Host.ISE.ISEOptions Options {get;}
PowerShellTabs Property Microsoft.PowerShell.Host.ISE.PowerShellTabCollection PowerShellTabs {get;}
To look at the options available for the Windows PowerShell ISE, choose the Options property. The result is shown here:
PS C:Usersedwils> $psISE.Options
SelectedScriptPaneState : Top
ShowToolBar : True
TokenColors : {[Attribute, #FFADD8E6], [Command, #FF0000FF], [CommandArgument, #FF8A2BE2]
, [CommandParameter, #FF000080]…}
DefaultOptions : Microsoft.PowerShell.Host.ISE.ISEOptions
FontSize : 20
FontName : Lucida Console
ErrorForegroundColor : #FFFF0000
ErrorBackgroundColor : #00FFFFFF
WarningForegroundColor : #FFFF8C00
WarningBackgroundColor : #00FFFFFF
VerboseForegroundColor : #FF0000FF
VerboseBackgroundColor : #00FFFFFF
DebugForegroundColor : #FF0000FF
DebugBackgroundColor : #00FFFFFF
OutputPaneBackgroundColor : #FFF0F8FF
OutputPaneTextBackgroundColor : #FFF0F8FF
OutputPaneForegroundColor : #FF000000
CommandPaneBackgroundColor : #FFFFFFFF
ScriptPaneBackgroundColor : #FFFFFFFF
ScriptPaneForegroundColor : #FF000000
ShowWarningForDuplicateFiles : True
ShowWarningBeforeSavingOnRun : False
UseLocalHelp : True
CommandPaneUp : False
To get an idea of what is returned via the Options property, pipe the returned object to the Get-Member cmdlet. This reveals that a Microsoft.PowerShell.Host.ISE.ISEOptions object is returned. The members of the ISEOptions object are shown here:
PS C:Usersedwils> $psISE.Options | gm
TypeName: Microsoft.PowerShell.Host.ISE.ISEOptions
Name MemberType Definition
—- ———- ———-
PropertyChanged Event System.ComponentModel.PropertyChangedEventHandler PropertyChang
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
RestoreDefaults Method System.Void RestoreDefaults()
RestoreDefaultTokenColors Method System.Void RestoreDefaultTokenColors()
ToString Method string ToString()
CommandPaneBackgroundColor Property System.Windows.Media.Color CommandPaneBackgroundColor {get;set;}
CommandPaneUp Property System.Boolean CommandPaneUp {get;set;}
DebugBackgroundColor Property System.Windows.Media.Color DebugBackgroundColor {get;set;}
DebugForegroundColor Property System.Windows.Media.Color DebugForegroundColor {get;set;}
DefaultOptions Property Microsoft.PowerShell.Host.ISE.ISEOptions DefaultOptions {get;}
ErrorBackgroundColor Property System.Windows.Media.Color ErrorBackgroundColor {get;set;}
ErrorForegroundColor Property System.Windows.Media.Color ErrorForegroundColor {get;set;}
FontName Property System.String FontName {get;set;}
FontSize Property System.Int32 FontSize {get;set;}
OutputPaneBackgroundColor Property System.Windows.Media.Color OutputPaneBackgroundColor {get;set;}
OutputPaneForegroundColor Property System.Windows.Media.Color OutputPaneForegroundColor {get;set;}
OutputPaneTextBackgroundColor Property System.Windows.Media.Color OutputPaneTextBackgroundColor {get;s…
ScriptPaneBackgroundColor Property System.Windows.Media.Color ScriptPaneBackgroundColor {get;set;}
ScriptPaneForegroundColor Property System.Windows.Media.Color ScriptPaneForegroundColor {get;set;}
SelectedScriptPaneState Property Microsoft.PowerShell.Host.ISE.SelectedScriptPaneState SelectedS…
ShowToolBar Property System.Boolean ShowToolBar {get;set;}
ShowWarningBeforeSavingOnRun Property System.Boolean ShowWarningBeforeSavingOnRun {get;set;}
ShowWarningForDuplicateFiles Property System.Boolean ShowWarningForDuplicateFiles {get;set;}
TokenColors Property System.Collections.Generic.IDictionary`2[[System.Management.Aut…
UseLocalHelp Property System.Boolean UseLocalHelp {get;set;}
VerboseBackgroundColor Property System.Windows.Media.Color VerboseBackgroundColor {get;set;}
VerboseForegroundColor Property System.Windows.Media.Color VerboseForegroundColor {get;set;}
WarningBackgroundColor Property System.Windows.Media.Color WarningBackgroundColor {get;set;}
WarningForegroundColor Property System.Windows.Media.Color WarningForegroundColor {get;set;}
The TokenColors property returns a dictionary object that contains the color mappings for the Windows PowerShell ISE tokenizer. This is used to provide the coloration for the scrip pane. Here are the color mappings:
PS C:Usersedwils> $psISE.Options.TokenColors
Key Value
— —–
Attribute #FFADD8E6
Command #FF0000FF
CommandArgument #FF8A2BE2
CommandParameter #FF000080
Comment #FF006400
GroupEnd #FF000000
GroupStart #FF000000
Keyword #FF00008B
LineContinuation #FF000000
LoopLabel #FF00008B
Member #FF000000
NewLine #FF000000
Number #FF800080
Operator #FFA9A9A9
Position #FF000000
StatementSeparator #FF000000
String #FF8B0000
Type #FF008080
Unknown #FF000000
Variable #FFFF4500
The colors are all instances of the System.Windows.Media.Color .NET Framework class. The reason for using these colors is that it presents a richer palette than the 16 colors that are expressed in the standard command prompt. Upon discovering this information, I thought “cool”; unfortunately, the colors are only moderately cool because they are not settable. I discovered this information by examining only the TokenColors member as seen here. You will notice that it says that TokenColors is get—and therefore not set (this is the last thing displayed.)
PS C:Usersedwils> $psISE.Options | gm tokencolors | ft -Wrap
TypeName: Microsoft.PowerShell.Host.ISE.ISEOptions
Name MemberType Definition
—- ———- ———-
TokenColors Property System.Collections.Generic.IDictionary`2[[System.Mana
0 comments