{"id":7301,"date":"2007-08-31T16:41:00","date_gmt":"2007-08-31T16:41:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/powershell\/2007\/08\/31\/export-demo\/"},"modified":"2019-02-18T13:16:33","modified_gmt":"2019-02-18T20:16:33","slug":"export-demo","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/powershell\/export-demo\/","title":{"rendered":"Export-Demo"},"content":{"rendered":"<p>A while ago I wrote a script START-DEMO which I use to give demos (You can get the latest\/greatest copy <a href=\"http:\/\/blogs.msdn.com\/powershell\/archive\/2007\/03\/06\/improved-start-demo-script.aspx\">HERE<\/a>. ) 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: <\/p>\n<ol>\n<li>It walks you through a set of commands and can explain what is going on. <\/li>\n<li>You actually run the real commands so you see how it really works. <\/li>\n<li>You can suspend out of the demo to try out variations of your own and then return picking up where you stopped. <\/li>\n<li>You have good control over the demo &#8211; 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. <\/li>\n<\/ol>\n<p>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&#8217;t want to write it. <span>J<\/span> <\/p>\n<p>Here is the script: <\/p>\n<p># Name: Export-Demo<br \/># Version: 1.0<br \/># Author: Microsoft<\/p>\n<p>param ($name)<br \/>foreach ($Name in @($Name))<br \/>{<br \/>$Help = Get-Help $Name -Example<br \/>foreach ($Example in $Help.Examples.Example) <br \/>{<br \/>&#8220;# &#8221; + $Example.Title<br \/>$Example.Remarks |<br \/>Where {$_.Text.Trim()} |<br \/>%{[Regex]::Split($_.Text,'(.{0,70}(?:\\s|$))&#8217;)}|<br \/>%{$x=$_.Trim(); if($x){&#8220;# $x&#8221;}}<br \/>($Example.Code -replace &#8220;C:\\\\PS&gt;&#8221;).Split(&#8220;`n&#8221;)|<br \/>where {$_.Trim()}<br \/>}<br \/>} <\/p>\n<p>BTW \u2013 10,000 thanks to Lee Holmes and his great blog. I used his <a href=\"http:\/\/www.leeholmes.com\/blog\/EmailQuotingAndWrappingIn59Bytes.aspx\">Email Quoting and Wrapping in 59 Bytes<\/a> as the source for that chewy looking REGEX code. (I&#8217;m soooo glad I didn&#8217;t have to figure that beast out. <span>J<\/span> ) <\/p>\n<p>Jeffrey Snover [MSFT]<br \/>Windows Management Partner Architect<br \/>Visit the Windows PowerShell Team blog at: <a href=\"http:\/\/blogs.msdn.com\/PowerShell\">http:\/\/blogs.msdn.com\/PowerShell<\/a><br \/>Visit the Windows PowerShell ScriptCenter at: <a href=\"http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx\">http:\/\/www.microsoft.com\/technet\/scriptcenter\/hubs\/msh.mspx<\/a> <\/p>\n","protected":false},"excerpt":{"rendered":"<p>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: [&hellip;]<\/p>\n","protected":false},"author":600,"featured_media":13641,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[],"class_list":["post-7301","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-powershell"],"acf":[],"blog_post_summary":"<p>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: [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/7301","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/users\/600"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/comments?post=7301"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/posts\/7301\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media\/13641"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/media?parent=7301"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/categories?post=7301"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/powershell\/wp-json\/wp\/v2\/tags?post=7301"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}