Summary: Ed Wilson, Microsoft Scripting Guy, talks about using Windows PowerShell to set up the ISE.
Hey, Scripting Guy! I am so excited—really excited! I have been selected to speak at a SQL Saturday event about Windows PowerShell. I could not have done it without you. I read your stuff every day, actually twice a day, and I come back to it during the day to help me with things I need to do. I never thought I would be talking about Windows PowerShell.
So I have a question, naturally. I would like to set up the ISE in my first script. I know how to run a script to set up my scratch folder, my working folder, and my presentation folder; in fact, I have them on PS Drives so I can easily get to them. I mean the ISE itself. For example, I will need to make things bigger, but I don’t want to worry about using ZoomIT that I see others using.
This is my first presentation, and I am more worried about not making a complete idiot of myself without worrying about some other piece of software. I know you do lots of presentations, what do you suggest?
Microsoft Scripting Guy, Ed Wilson, is here. The Scripting Wife has not stopped talking about the MVP Summit—and it has been over for almost a week. She met so many new people, including many of the way cool members of the Microsoft Operations Management Suite (OMS). She said, “I even got to meet Jeremy Winters! He is the Jeffery Snover of OMS.” Coming from a Windows PowerShell MVP, that is high praise indeed. She was able to get into the Jeremy Unplugged session, and said it totally rocked.
Set up the ISE for presentations
So yes, GG, the Windows PowerShell ISE has an object model, and I do indeed use that object model to configure the ISE the way I like it for presentations. There are three steps that I follow:
- Read in the original settings.
- Make the changes to my newly desired settings.
- Change the settings back to the originals.
In addition, depending on my demo, I also have a presentation clean-up script. So if my presentation creates a bunch of folders, files, and shares, for example, my clean-up script will delete those folders and files and remove the shares. This makes it easy to run the demo a second time without having to worry if something is there. In fact, I usually create the clean-up script at the same time I am creating my demo. (This is usually because it takes me several times to get the demo to where it is perfect, and I need the reset capabilities.)
Seven items I like to set
There are seven settings I like to prepare when I get ready to make a Windows PowerShell presentation:
- Turn off the tool bar.
- Maximize the script pane.
- Set the Zoom to an appropriate level (I generally use 120%).
- Set the Font size to an appropriate size (I like to use 10).
- Increase the IntelliSense timeout value (maybe five seconds).
- Turn off the warning about saving before running.
- Turn off the warning about duplicate files.
The reason I like the first four items is that they make the script easier to read and see. All this depends on the resolution that the beamer in the classroom will support. If the resolution is very high, I may need to change my settings to a higher value. On the other hand, if the resolution is very low, I may need to reduce my settings so I can show the script without having to scroll.
The final three items are used for convenience while making a presentation. Often I want the IntelliSense to remain up for a longer period of time so the audience can better see what I am doing, and to have time to read the IntelliSense before it quickly disappears. The two warnings are turned off to avoid harassing me while I am presenting. I have practiced the presentation many times, and presumably, I have it backed up to my OneDrive, so I do not want a bunch of distracting prompts.
Read the settings and store them in variables
The first thing I want to do is to read the seven settings and store my current configuration values into variables. I will use these after my presentation is over as part of my clean-up script. To do this, I simply access each of the values and store them in variables:
$toolbar = $psISE.Options.ShowToolBar
$scriptPane = $psISE.Options.SelectedScriptPaneState
$zoom = $psISE.Options.Zoom
$fontSize = $psISE.Options.FontSize
$intellisense = $psISE.Options.IntellisenseTimeoutInSeconds
$runWarning = $psISE.Options.ShowWarningBeforeSavingOnRun
$dupFile = $psISE.Options.ShowWarningForDuplicateFiles
Configure the ISE for the presentation
Now that I have my settings stored in a series of variables, I can make the assignments I want to use for my presentation. It is a straightforward value assignment for each of the ISE options. If you do not like these values, you can change them as required.
Note Do not disable the Toolbar unless you know the keyboard shortcuts to enable you to run a script (F5), to run a portion of a script (F8), and to close a selected file (CTRL-F4).
Here is that script:
$psISE.Options.ShowToolBar = $false
$psISE.Options.SelectedScriptPaneState = “maximized”
$psISE.Options.Zoom = 120
$psISE.Options.FontSize = 10
$psISE.Options.IntellisenseTimeoutInSeconds = 5
$psISE.Options.ShowWarningBeforeSavingOnRun = $false
$psISE.Options.ShowWarningForDuplicateFiles = $false
Revert the ISE settings
When I am finished with my presentation, I revert the ISE back to my “work” preferences. To do this, the initial code is basically flipped. That is, now I go through each of my settings and set them equal to the values I stored in my variables. I actually copy the code from the previous section (Configure the ISE for the presentation), and then set the values to my variables containing the original values. This is shown here:
$psISE.Options.ShowToolBar = $toolbar
$psISE.Options.SelectedScriptPaneState = $scriptPane
$psISE.Options.Zoom = $zoom
$psISE.Options.FontSize = $fontSize
$psISE.Options.IntellisenseTimeoutInSeconds = $intellisense
$psISE.Options.ShowWarningBeforeSavingOnRun = $runWarning
$psISE.Options.ShowWarningForDuplicateFiles = $dupFile
I use each section of code by highlighting it and running only that selection (by pressing F8).
GG, that is all there is to using Windows PowerShell to configure the Windows PowerShell ISE. 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