Working on my PowerShell for Developers presentation I’m doing at our upcoming Devscovery Conference in NYC (April 27-29) it was a no brainer to use Jeffrey Snover’s excellent Start-Demo script (much improved by Joel Bennett). If you’re a bad typist like I am having the demo script is a godsend when showing techniques in a tool like PowerShell. It’s also a great example of a PowerShell script for someone learning PowerShell.
As I worked out my demos, I still needed to have some PowerPoint slides to point out key concepts and things like URLs. As I was putting the slides together something was bothering me. Why was I using PowerPoint? I’m going to be a session on PowerShell. Shouldn’t I be using PowerShell? The first rule of the PowerShell club is to use PowerShell! That’s the second rule as well.
What we were missing was PowerShellPoint, but no longer. At the bottom of this article is the Start-PowerShell.ps1 script I wrote to do my presentation. I’m hoping that others doing PowerShell presentations will use it so PowerShell is the only tool you need to demonstrate PowerShell. So to demo PowerShellPoint, I’ll use PowerShellPoint itself. Just call me Captain Recursion!
Just like PowerPoint, I show that black screen. Press the “p” key to move back into the slides.
Below is the script. If you want to download the script and the demo presentation, click here.
Please do let me know if you find Start-PowerShellPoint useful and if you do extend it!
#requires -version 2
# (c) 2010 by John RobbinsWintellect – Do whatever you want to do with it
# as long as you give credit.
<#.SYNOPSIS
PowerShellPoint is the only way to do a presentation on PowerShell. All
PowerShell all the time!
.DESCRIPTION
If you’re doing a presentation on using PowerShell, there’s Jeffrey Snover’s
excellent Start-Demo, (updated by Joel Bennett (http://poshcode.org/705)) for
running the actual commands. However, to show discussion and bullet points,
everyone switches to PowerPoint. That’s crazy! EVERYTHING should be done in
PowerShell when presenting PowerShell. Hence, PowerShellPoint!
To create your “slides” the format is as follows:
Slide titles start with an exclamation point.
Comment (#) are ignored.
The slide points respect any white space and blank lines you have.
All titles and slide points are indented one character.
Here’s an example slide file:
——
# A comment line that’s ignored.
!First Title
Point 1
Sub Point A
Point 2
Sub Point B
!Second Title
Point 3
Sub Point C
Point 4
Sub Point D
!Third Title
Point 5
Sub Point E
——
The script will validate that no slides contain more points than can be
displayed or individual points will wrap.
The default is to switch the window to 80 x 25 but you can specify the window size
as parameters to the script.
The script properly saves and restores the original screen size and buffer on
exit.
When presenting with PowerShellPoint, use the ‘h’ command to get help.
.PARAMETER File
The file that contains your slides. Defaults to .Slides.txt.
.PARAMETER Width
The width in characters to make the screen and buffer. Defaults to 80.
.PARAMETER Height
The height in characters to make the screen and bugger. Defaults to 25.
#>
param( [string]$File = “.Slides.txt”,
[int]$Width = 80,
[int]$Height = 25)
Set-StrictMode –version Latest
$scriptVersion = “1.0”
# Constants you may want to change.
# The foreground and background colors for the title and footer text.
$titleForeground = “Yellow”
$titleBackground = “Black”
# Slide points foreground and background.
$textBackGround = $Host.UI.RawUI.BackgroundColor
$textForeGround = $Host.UI.RawUI.ForegroundColor
# A function for reading in a character swiped from Jaykul’s
# excellect Start-Demo 3.3.3.
function Read-Char()
{
$inChar=$Host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyUp”)
# loop until they press a character, so Shift or Ctrl, etc don’t terminate us
while($inChar.Character -eq 0)
{
$inChar=$Host.UI.RawUI.ReadKey(“NoEcho,IncludeKeyUp”)
}
return $inChar.Character
}
function ProcessSlides($inputFile)
{
$rawLines = Get-Content $inputFile
# Contains the actual slides. The key is the slide number and the value are the
# text lines.
$slides = @{}
# The slide number I’m processing.
$slideNumber = 0
[string[]]$lines = $null
# Process the raw text by reading it into the hash table.
for ($i = 0 ; $i -lt $rawLines.Count ; $i++ )
{
# Skip any comment lines.
if ($rawLines[$i].Trim(” “).StartsWith(“#”))
{
continue
}
# Lines starting with “!” are a title.
if ($rawLines[$i].StartsWith(“!”))
{
if ($lines -ne $null)
{
$slides.Add($slideNumber,$lines)
$lines = $null
}
$slideNumber++
if ($rawLines[$i].Substring(1).Length -eq