Welcome to MSDN Blogs Sign in | Join | Help

Export-Demo

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()} |
%{[Regex]::Split($_.Text,'(.{0,70}(?:\s|$))')}|
%{$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

Published Friday, August 31, 2007 9:41 PM by PowerShellTeam

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# MSDN Blog Postings » Export-Demo

Friday, August 31, 2007 6:47 PM by MSDN Blog Postings » Export-Demo

# re: Export-Demo

There was a recent online discussion where most seemed to agree that posting online code with built-in aliases shouldn't be done.  Might confuse the newcomers...

Saturday, September 01, 2007 5:21 PM by marco.shaw

# re: Export-Demo

> There was a recent online discussion where most seemed to agree that posting online code with built-in aliases shouldn't be done.

I'd agree with that for everything except the -OBJECT shortcuts (e.g. WHERE-OBJECT -> WHERE).  Is there another alias that I used?

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

Saturday, September 01, 2007 7:22 PM by PowerShellTeam

Leave a Comment

(required) 
required 
(required) 
 
Page view tracker