PowerShell Team

A while ago I wrote a script START-DEMO which I use to give demos (You can get the latest/greatest copy HERE. ) This script is also a great teaching tool. You can create your own demo.txt file with commands and explanations and then people can run it using Start-Demo. The great things about this are:

  1. It walks you through a set of commands and can explain what is going on.
  2. You actually run the real commands so you see how it really works.
  3. You can suspend out of the demo to try out variations of your own and then return picking up where you stopped.
  4. You have good control over the demo – you can skip lines, you can repeat things, you can go to a line in the demo, you can find all the lines that match a regular expression. Etc.

Our test manager Michael Naixin Li asked me about how this related to the examples we have in our help system. In response, I wrote the script Export-Demo.ps1 (code below). This script takes one or more help topics and extracts the EXAMPLEs to create a stream of text which can be saved and run as a demo.txt file. Our Help XML cause this script to be a bit chewy. This is the sort of script where you are glad that someone on the internet took the time to write it because you want it but wouldn’t want to write it. J

Here is the script:

# Name: Export-Demo
# Version: 1.0
# Author: Microsoft

param ($name)
foreach ($Name in @($Name))
$Help = Get-Help $Name -Example
foreach ($Example in $Help.Examples.Example)
“# ” + $Example.Title
$Example.Remarks |
Where {$_.Text.Trim()} |
%{$x=$_.Trim(); if($x){“# $x”}}
($Example.Code -replace “C:\\PS>”).Split(“`n”)|
where {$_.Trim()}

BTW – 10,000 thanks to Lee Holmes and his great blog. I used his Email Quoting and Wrapping in 59 Bytes as the source for that chewy looking REGEX code. (I’m soooo glad I didn’t have to figure that beast out. J )

Jeffrey Snover [MSFT]
Windows Management Partner Architect
Visit the Windows PowerShell Team blog at: http://blogs.msdn.com/PowerShell
Visit the Windows PowerShell ScriptCenter at: http://www.microsoft.com/technet/scriptcenter/hubs/msh.mspx


Discussion is closed.

Feedback usabilla icon