Summary: Ed Wilson, Microsoft Scripting Guy, talks about resetting the Windows PowerShell ISE settings to the defaults.
Microsoft Scripting Guy, Ed Wilson, is here. One of the great things about Windows PowerShell is that it is highly configurable. Not only the things that I can configure, but Windows PowerShell itself. The behaviors in the Windows PowerShell console and the Windows PowerShell ISE can be quickly changed. One of the best ways to do this is to use a Windows PowerShell profile. I like to create specific profiles for certain environments instead of one big monolithic profile. In fact, I like to use modules to encapsulate certain pieces of functionality.
But with all that tweaking, changing, and configuring, it is easy to get things really messed up. Simply exiting the program and reloading it does not always reset things. In fact, rebooting the computer does not always reset stuff. One of my rules has always been that when I write something that makes a change, I like to also write something that will undo that change. It is a rather hard-fought rule that I learned after having to reinstall Windows a few times.
Anyway, since I have been talking about making changes to the Windows PowerShell ISE, I thought I would share how to reset the defaults.
Not all defaults are default…
The first thing to learn is that there are many levels of defaults in the Windows PowerShell ISE. For example, there are console pane token colors, script pane token colors, and XML token colors.
I can set the token colors for the Windows PowerShell ISE script pane by using the TokenColors object. Each token is an assignment value. In the previous image, I set the comment color to red. It will affect only the script pane, not the console pane. To reset the default token colors used in the script pane, I use RestoreDefaultTokenColors method. I found this method by examining the Options object:
PS C:\> $psISE.Options | gm -MemberType Method
Name MemberType Definition
---- ---------- ----------
Equals Method bool Equals(System.Object obj)
GetHashCode Method int GetHashCode()
GetType Method type GetType()
RestoreDefaultConsoleTokenColors Method void RestoreDefaultConsoleTokenC...
RestoreDefaults Method void RestoreDefaults()
RestoreDefaultTokenColors Method void RestoreDefaultTokenColors()
RestoreDefaultXmlTokenColors Method void RestoreDefaultXmlTokenColors()
ToString Method string ToString()
When I use the RestoreDefaultTokenColors method, the comment in the script automatically returns to green. Here is that command:
The command and the associated output are shown here:
I can do the same thing for the Windows PowerShell ISE console. In the following image, I set the console comment token to red, and when I type a comment, it is red. Note that the comment in the script pane remains unaffected.
To restore the console tokens, I use the RestoreDefaultConsoleTokenColors method:
If I have made changes (say putting things into a presentation mode for a presentation that I want to do), and I would like to just restore everything to its default value, I can use the more generic RestoreDefaults method. This resets everything—font size, zoom level, even the “never show this prompt again” prompt values. The command is shown here:
As you can see in the following image, my fonts and zoom levels have reverted to default values:
To be honest, if you have customized your ISE in any way, you really don’t want to use this more extreme method of resetting the defaults. In fact, all four reset default methods are pretty heavy handed, and it is much better to store your particular defaults, and then restore those defaults when needed, rather than the methods listed here. Of course, if things are totally hosed, this is a good way to get back to the beginning without reinstalling Windows!
That is all there is to using the defaults. Join me tomorrow when I will talk about more cool stuff.
I invite you to follow me on Twitter and Facebook. If you have any questions, send email to me at email@example.com, or post your questions on the Official Scripting Guys Forum. See you tomorrow. Until then, peace.
Ed Wilson, Microsoft Scripting Guy