<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>ps1.soapyfrog.com &#187; Utility</title>
	<atom:link href="http://ps1.soapyfrog.com/category/utility/feed/" rel="self" type="application/rss+xml" />
	<link>http://ps1.soapyfrog.com</link>
	<description>doing inappropriate things with powershell</description>
	<lastBuildDate>Sun, 26 Aug 2007 22:01:08 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>IRC chat bot and monitor</title>
		<link>http://ps1.soapyfrog.com/2007/01/31/irc-chat-bot-and-monitor/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/31/irc-chat-bot-and-monitor/#comments</comments>
		<pubDate>Wed, 31 Jan 2007 14:52:16 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/31/irc-chat-bot-and-monitor/</guid>
		<description><![CDATA[Last weekend, I asked my wife if she could think of anything inappropriate or unusual to do with PowerShell. She came up with some good ideas and one of them was to write a chat/IM client. A full client takes time, so with a nod toward PowerShell&#8217;s administrative uses, I wrote a script that forms [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend, I asked my wife if she could think of anything inappropriate or unusual to do with PowerShell. She came up with some good ideas and one of them was to write a chat/IM client.</p>
<p>A full client takes time, so with a nod toward PowerShell&#8217;s administrative uses, I wrote a script that forms the basis of an <a href="http://www.faqs.org/rfcs/rfc1459.html">IRC</a> chat bot.</p>
<p>This script can be used to pipe messages to a chat channel and/or join a set of channels, returning all messages posted there.</p>
<p>I&#8217;ve sure most of you out there use <del>Microsoft</del> <del>MSN</del> Windows Live Messenger, or even Yahoo! or AOL, so this may just serve as an example of synchronous TCP/IP messaging in PowerShell.</p>
<p><strong>You can download the script here: <a href='http://ps1.soapyfrog.com/wp-content/uploads/2007/01/chat-ircps1.txt' title='chat-irc.ps1'>chat-irc.ps1</a>. </strong></p>
<p>You may need to unblock it according the the instructions in <code>help about_signing</code>.</p>
<p><span id="more-52"></span></p>
<p><strong>Summary of use</strong></p>
<p>This script operates in two modes, sender, or monitor (or both).</p>
<p>Regardless, you need to set up connection info in a hash, eg:</p>
<pre>$coninfo = @{
  server="chat.freenode.net"
  port=6667
  nick="mynick"
  user="myuser"
  pwd="my password if required"
  realname="This is my real name"
  hostname"This is my host name, but is generally ignored"
}
</pre>
<p> <img src='http://ps1.soapyfrog.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  I&#8217;ve been using chat.freenode.net and my own local hybrid irc server for testing.</p>
<p>To send a message to the #test channel and quit:</p>
<p><code>chat-irc -coninfo $coninfo -sendto "#test" -message "Hello, world"</code></p>
<p>To send output from the pipeline, eg a file:</p>
<p><code>gc file.txt | chat-irc -coninfo $coninfo</code></p>
<p>To monitor a channel for messages:</p>
<p><code>chat-irc -coninfo $coninfo -monitor "#test"</code></p>
<p>This will stay connected until you ctrl+C, are killed by the server, etc, or if <code>chat-irc</code> is sent the message &#8220;stopstopstop&#8221;.</p>
<p>The output is formatted strings containing from/to/message, however these strings are annotated with noteproperties, so you can do:</p>
<p><code>chat-irc -coninfo $coninfo -monitor "#test" select *</code></p>
<p>The properties include sender info (<code>user</code>,<code>host</code>,<code>nick</code>,<code>full</code>), <code>date</code>, <code>to</code> and <code>message</code>.</p>
<p>These two modes can be used together, and the monitor parameter can take<br />
more than one channel, so for example:</p>
<p><code>chat-irc -coninfo $coninfo -monitor "#foo","#bar" -sendto "#test" -message "hello"</code></p>
<p>will send &#8220;hello&#8221; to #test then monitor #foo,#bar and #test for messages.</p>
<p>By default, only messages sent to the monitored channel(s) are output, but you can include private messages with the switch <code>-incprivate</code>, the message of the day with <code>-incmotd</code>, notices with <code>-incnotice</code> and other with <code>-incother</code>.</p>
<p>You can see debug info with -debug and verbose output (all messages)<br />
with -verbose. These latter switches just set the $DebugPreference and $VerbosePreference variables to &#8220;Continue&#8221; in the script&#8217;s scope See <a href="http://ps1.soapyfrog.com/2007/01/29/debug-and-verbose-colouring/">Debug and Verbose Colouring</a> for more information on that.</p>
<p><strong>Examples</strong></p>
<p>Here we get chat-irc to monitor the channel #test2 whilst I (millinad) chat to it in a normal IRC chat client.</p>
<pre>PS> chat-irc -coninfo $coninfo -monitor "#test2" | select date,nick,message|ft -wrap

date                         nick                        message
----                         ----                        -------
31/01/2007 14:21:20          millinad                    hello soapybot
31/01/2007 14:21:30          millinad                    nice to see you here
31/01/2007 14:21:38          millinad                    time for you to go now
31/01/2007 14:21:40          millinad                    stopstopstop
</pre>
<p>and in the chat client:</p>
<pre> * soapybot (n=soapybot@*******) has joined #test2
 <millinad> hello soapybot
 <millinad> nice to see you here
 <millinad> time for you to go now
 <millinad> stopstopstop
 * soapybot (n=soapybot@*******) has left #test2
</pre>
<p>Now lets do the same thing again, but with debug switched on and private messages enabled. We&#8217;ll turn off the pipeline formatting.</p>
<pre style='color: #000; background-color: #ccc; '>PS&gt; chat-irc -coninfo $coninfo -monitor &#34;#test2&#34; -incprivate -debug
<span style='color: #888; background-color: #ccc'>DEBUG: Using connection info:</span>
<span style='color: #888; background-color: #ccc'>DEBUG: server: chat.freenode.net</span>
<span style='color: #888; background-color: #ccc'>DEBUG: port: 6667</span>
<span style='color: #888; background-color: #ccc'>DEBUG: user: soapybot</span>
<span style='color: #888; background-color: #ccc'>DEBUG: nick: soapybot</span>
<span style='color: #888; background-color: #ccc'>DEBUG: pwd: ************</span>
<span style='color: #888; background-color: #ccc'>DEBUG: realname: powershell bot using soapyfrog inout-irc.ps1</span>
<span style='color: #888; background-color: #ccc'>DEBUG: hostname: localhost</span>
freenode-connect : soapybot : ☺VERSION☺
<span style='color: #888; background-color: #ccc'>DEBUG: I *may* have joined channel #test2</span>
millinad : #test2 : hello again
millinad : #test2 : i see you received a ctcp message above. pity you don&#39;t understa
nd them.
millinad : #test2 : time to go again
millinad : soapybot : stopstopstop
</pre>
<p>In the last line, I sent soapybot a direct message to stopstopstop rather than to the channel. Without <code>-incprivate</code> this message would not have been output.</p>
<p><strong>How it works</strong></p>
<p>The script connects to the chat server using <code>System.Net.Sockets.TcpClient</code>. Messages are sent using a <code>System.IO.StreamWriter</code> with ASCII encoding. .NET doesn&#8217;t seem to mind of non ASCII chars are translated in this way.</p>
<p>Reading messages is done differently. We can&#8217;t use a <code>System.IO.StreamReader</code>, because <code>ReadLine</code> blocks if there isn&#8217;t a full line available. </p>
<p>We can&#8217;t use asynchronous reading because it&#8217;s quite hard to use scriptblocks as delegates (although that might change in future versions of PowerShell), and threading is a bit of an unknown quantity in PowerShell.</p>
<p>Instead I use the <code>Net.Sockets.NetworkStream</code> with its <code>DataAvailable</code> and <code>ReadByte</code>. This means I can check if data is available, and if not, idle or send messages, then check again. Reading byte by byte makes the code easier to read, and it&#8217;s not too big a performance hit, we&#8217;re bound by the network and the speed of people typing <img src='http://ps1.soapyfrog.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
<p>Lines are processed in the <code>process-line</code> function where the line is parsed and checked for known numeric responses and commands.</p>
<p>The default handling of a message is in the function <code>_onprivmsg</code> where the message is just formatted and decorated and place into the output pipeline.</p>
<p> <img src='http://ps1.soapyfrog.com/wp-includes/images/smilies/icon_idea.gif' alt=':idea:' class='wp-smiley' />  If you wanted to have this bot do something else, you would do it here.</p>
<p><strong>A good chat citizen</strong></p>
<p>This script tries to be a good citizen by throttling it&#8217;s message sending with 1 second delays between messages. This is set with the <code>-throttledelay</code> parameter (milliseconds). The amount of time the script idles when there is no data from the server is 2 seconds, set with the <code>-idledelay</code> parameter.</p>
<p>Even with these values, it&#8217;s still possibly to be killed by a server for flooding. You may want to ask server admin to reduce the flood spec for your bot, or increase the throttledelay.</p>
<p>For example, at chat.freenode.net, piping the output from a directory listing would still cause a flood.</p>
<p>Enjoy <img src='http://ps1.soapyfrog.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/31/irc-chat-bot-and-monitor/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Updated get-bufferhtml</title>
		<link>http://ps1.soapyfrog.com/2007/01/25/updated-get-bufferhtml/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/25/updated-get-bufferhtml/#comments</comments>
		<pubDate>Thu, 25 Jan 2007 14:52:11 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Announce]]></category>
		<category><![CDATA[Cool]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/25/updated-get-bufferhtml/</guid>
		<description><![CDATA[A while back, I posted an article: Console screen grabs in html. I fixed some bugs and added a couple of new features to the script get-bufferhtml.ps1, and have updated the article with examples. Enjoy!]]></description>
			<content:encoded><![CDATA[<p>A while back, I posted an article: <a href="/2007/01/06/console-screen-grabs-in-html/">Console screen grabs in html</a>.</p>
<p>I fixed some bugs and added a couple of new features to the script <a id="p27" href="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/get-bufferhtmlps1.txt" title="get-bufferhtml.ps1">get-bufferhtml.ps1</a>, and have updated the <a href="/2007/01/06/console-screen-grabs-in-html/">article</a> with examples.</p>
<p>Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/25/updated-get-bufferhtml/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Banners</title>
		<link>http://ps1.soapyfrog.com/2007/01/19/banners/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/19/banners/#comments</comments>
		<pubDate>Fri, 19 Jan 2007 14:37:46 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/19/banners/</guid>
		<description><![CDATA[In the old days, when you printed something out, you&#8217;d have to wander down to the print room and find your output in a stack of fanfold with the job name printed as a large banner on the top. I miss those days so I wrote a banner script to do this: It&#8217;s a script, [...]]]></description>
			<content:encoded><![CDATA[<p>In the old days, when you printed something out, you&#8217;d have to wander down to the print room and find your output in a stack of fanfold with the job name printed as a large banner on the top. I miss those days so I wrote a banner script to do this:</p>
<p><img id="image43" src="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/banner1.gif" alt="banner screenshot" /></p>
<p><span id="more-42"></span></p>
<p>It&#8217;s a script, so execute it directly. It takes a string (or array of strings) as the first argument and two optional parameters, <tt>-fg <em>char</em></tt> to set the foreground character and <tt>-bg <em>char</em></tt> for the background character. The defaults are a solid block and a space. For example:</p>
<pre style='color: #eeedf0; background-color: #012456;'>PS> banner "hello","world" -fg "/"
/   / ///// /     /      ///
/   / /     /     /     /   /
///// ///   /     /     /   /
/   / /     /     /     /   /
/   / ///// ///// /////  ///

/   /  ///  ////  /     ////
/   / /   / /   / /     /   /
/ / / /   / ////  /     /   /
// // /   / /   / /     /   /
/   /  ///  /   / ///// ////

PS>
</pre>
<p><strong>You can download the script here: <a id="p40" href="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/bannerps1.txt">banner.ps1</a>.</strong></p>
<p>Don&#8217;t copy/paste this &#8211; save it directly from the above link. It contains formatted text that may get corrupted.</p>
<p>Enjoy!</p>
<p>[Update] The script will also take input from the pipeline so you can do things like:</p>
<p><tt>[enum]::getnames([consolecolor]) | where { $_ -notlike "dark*"} | banner -fg "#"</tt></p>
<p>to get this:</p>
<pre style='color: #eeedf0; background-color: #012456'>
####  #      ###   ###  #   #
#   # #     #   # #   # #  #
####  #     ##### #     ###
#   # #     #   # #   # #  #
####  ##### #   #  ###  #   #                                                                             

 ###  ####   ###  #   #
#     #   # #   #  # #
#  ## ####  #####   #
#   # #   # #   #   #
 ###  #   # #   #   #                                                                                     

####  #     #   # #####
#   # #     #   # #
####  #     #   # ###
#   # #     #   # #
####  #####  ###  #####                                                                                   

 ###  ####  ##### ##### #   #
#     #   # #     #     ##  #
#  ## ####  ###   ###   # # #
#   # #   # #     #     #  ##
 ###  #   # ##### ##### #   #                                                                             

 ###  #   #  ###  #   #
#   #  # #  #   # ##  #
#       #   ##### # # #
#   #   #   #   # #  ##
 ###    #   #   # #   #                                                                                   

####  ##### ####
#   # #     #   #
####  ###   #   #
#   # #     #   #
#   # ##### ####                                                                                          

#   #  ###   ###  ##### #   # #####  ###
## ## #   # #     #     ##  #   #   #   #
# # # ##### #  ## ###   # # #   #   #####
#   # #   # #   # #     #  ##   #   #   #
#   # #   #  ###  ##### #   #   #   #   #                                                                 

#   # ##### #     #      ###  #   #
 # #  #     #     #     #   # #   #
  #   ###   #     #     #   # # # #
  #   #     #     #     #   # ## ##
  #   ##### ##### #####  ###  #   #                                                                       

#   # #   #  ###  ##### #####
#   # #   #   #     #   #
# # # #####   #     #   ###
## ## #   #   #     #   #
#   # #   #  ###    #   #####                                                                             
</pre>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/19/banners/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Convert images to text (ASCII art)</title>
		<link>http://ps1.soapyfrog.com/2007/01/07/convert-images-to-text-ascii-art/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/07/convert-images-to-text-ascii-art/#comments</comments>
		<pubDate>Sun, 07 Jan 2007 11:15:49 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/07/convert-images-to-text-ascii-art/</guid>
		<description><![CDATA[Recently, whilst messing with sprites and the Grrr framework, I got thinking about better graphics for games. As PowerShell is very slow at doing console atomic write operations, a game should really have fewer, larger sprites. I then thought about ASCII art, and wouldn&#8217;t it be great if PowerShell could convert existing images (jpg, png) [...]]]></description>
			<content:encoded><![CDATA[<p>Recently, whilst messing with sprites and the <a href="/2007/01/03/grrr/" rel="self" title="Grrr!">Grrr</a> framework, I got thinking about better graphics for games. </p>
<p>As PowerShell is very slow at doing console atomic write operations, a game should really have fewer, larger sprites. I then thought about ASCII art, and wouldn&#8217;t it be great if PowerShell could convert existing images (jpg, png) and produce lines of text for use with Grrr&#8217;s create-image function.</p>
<p>So my morning&#8217;s work is a PowerShell script that does just that.</p>
<p>You can download it here: <a id="p26" href="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/convert-image2textps1.txt">convert-image2text.ps1 (as a text file)</a></p>
<p>(If you&#8217;re reading this from the RSS feed, the link may be broken &#8211; open the blog page if so)</p>
<p>Unfortunately, it&#8217;s only monochrome. I had a lot of trouble getting a reasonable conversion of RGB or HSV to the console&#8217;s limited colour palette and character range, so in the end, I removed it.</p>
<p>The script uses System.Drawing and demonstrates one (a good?) way of adding an assembly to PowerShell.</p>
<p>Usage:</p>
<pre>./convert-image2text.ps1 imagefile 
      [ -maxwidth nchars ] [-palette ascii | shade | bw ]
</pre>
<p>
Here&#8217;s an example using the default -palette ascii option:</p>
<p><img id="image21" src="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/monolisa-ascii.gif" alt="monolisa-ascii.gif" /></p>
<p>Here&#8217;s the same with the -palette shade option:</p>
<p><img id="image22" src="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/monolisa-shade.gif" alt="monolisa-shade.gif" /><br />
Both are from this source image (click to see full size):</p>
<p><a href="/assets/monalisa.jpg" rel="external"><br />
  <img alt="monalisa-small" src="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/monalisa-small.jpg" /><br />
</a></p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/07/convert-images-to-text-ascii-art/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Console screen grabs in html</title>
		<link>http://ps1.soapyfrog.com/2007/01/06/console-screen-grabs-in-html/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/06/console-screen-grabs-in-html/#comments</comments>
		<pubDate>Sat, 06 Jan 2007 19:22:47 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Cool]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Utility]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/06/console-screen-grabs-in-html/</guid>
		<description><![CDATA[[Updated 25 Jan 2007, well rewritten ] Something I find myself doing a lot is getting a screen shot of a PowerShell console window and posting it some place. Unfortunately, its always a bitmap, and occasionally, I want it as formatted text. Now, the console is readable via $host.ui.rawui.GetBufferContents, so I wrote a small(ish) script [...]]]></description>
			<content:encoded><![CDATA[<p>[Updated 25 Jan 2007, well rewritten <img src='http://ps1.soapyfrog.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  ]</p>
<p>Something I find myself doing a lot is getting a screen shot of a PowerShell console window and posting it some place. Unfortunately, its always a bitmap, and occasionally, I want it as formatted text.</p>
<p>Now, the console is readable via <code>$host.ui.rawui.GetBufferContents</code>, so I wrote a small(ish) script to do just that, outputting lines of html.</p>
<p>You can download the script here <a id="p27" href="http://ps1.soapyfrog.com/wp-content/uploads/2007/01/get-bufferhtmlps1.txt">get-bufferhtml.ps1</a>.</p>
<p>Put the script somewhere so you can run it by name.</p>
<p>By default, the script will grab lines from the top of the buffer up to, but not including the current line, so if you type in this sequence:</p>
<pre>PS> get-bufferhtml > out.html
PS> get-date
PS> asdasda
PS> get-bufferhtml > out.html
</pre>
<p>You end up with this:</p>
<pre style='color: #eeedf0; background-color: #012456; '>PS> get-bufferhtml > out.html
<span style='color: #ff0; background-color: #000'>WARNING: There must be one or more lines to get</span>
PS> get-date                                                            

25 January 2007 14:17:42                                                

PS> asdasda
<span style='color: #f00; background-color: #000'>The term 'asdasda' is not recognized as a cmdlet, function, operable pr</span>
<span style='color: #f00; background-color: #000'>ogram, or script file. Verify the term and try again.</span>
<span style='color: #f00; background-color: #000'>At line:1 char:7</span>
<span style='color: #f00; background-color: #000'>+ asdasda <span><</span><span><</span><span><</span><span><</span> </span>
</pre>
<p>Note that the first line produced a warning, the second showed the date, the third produced an error and the last command (not shown) produce the above.</p>
<p>That output was then just pasted into this blog entry.</p>
<p><span id="more-7"></span></p>
<p>There are a few options you can play with, all of them described in the comments at the top of the script.</p>
<p>One option is to change the palette. If we continue with the command <code>get-bufferhtml -palette print > out2.html</code>, we get this:</p>
<pre style='color: #000; background-color: #eee; '>PS> get-bufferhtml > out.html
<span style='color: #440; background-color: #fff'>WARNING: There must be one or more lines to get</span>
PS> get-date                                                            

25 January 2007 14:17:42                                                

PS> asdasda
<span style='color: #f00; background-color: #fff'>The term 'asdasda' is not recognized as a cmdlet, function, operable pr</span>
<span style='color: #f00; background-color: #fff'>ogram, or script file. Verify the term and try again.</span>
<span style='color: #f00; background-color: #fff'>At line:1 char:7</span>
<span style='color: #f00; background-color: #fff'>+ asdasda <span><</span><span><</span><span><</span><span><</span> </span>
PS> get-bufferhtml > out.html
</pre>
<p>This is easier on the printer!</p>
<p>Another palette is &#8220;standard&#8221; &#8211; the one used by default if you open a &#8220;Command Prompt&#8221; or indeed any other console application. The key difference here is that DarkMagenta and DarkYellow <em>are</em>. I&#8217;ve no idea why the PowerShell team decided to <a href="/2007/01/08/what-colour-is-yours/">mess the colour palette</a>.</p>
<p>Continuing with the command <code>get-bufferhtml -palette standard > out3.html</code>, we get this:</p>
<pre style='color: #880; background-color: #808; '>PS> get-bufferhtml > out.html
<span style='color: #ff0; background-color: #000'>WARNING: There must be one or more lines to get</span>
PS> get-date                                                            

25 January 2007 14:17:42                                                

PS> asdasda
<span style='color: #f00; background-color: #000'>The term 'asdasda' is not recognized as a cmdlet, function, operable pr</span>
<span style='color: #f00; background-color: #000'>ogram, or script file. Verify the term and try again.</span>
<span style='color: #f00; background-color: #000'>At line:1 char:7</span>
<span style='color: #f00; background-color: #000'>+ asdasda <span><</span><span><</span><span><</span><span><</span> </span>
PS> get-bufferhtml > out.html
PS> get-bufferhtml -palette print > out2.html
</pre>
<p>The default font is whatever your browser wants to use for the PRE tag, but you can override this if you issue a command like <code>get-bufferhtml -palette print -font "tahoma" > out4.html</code> and get:</p>
<pre style='color: #000; background-color: #eee; font-family: "tahoma"; '>PS> get-bufferhtml > out.html
<span style='color: #440; background-color: #fff'>WARNING: There must be one or more lines to get</span>
PS> get-date                                                            

25 January 2007 14:17:42                                                

PS> asdasda
<span style='color: #f00; background-color: #fff'>The term 'asdasda' is not recognized as a cmdlet, function, operable pr</span>
<span style='color: #f00; background-color: #fff'>ogram, or script file. Verify the term and try again.</span>
<span style='color: #f00; background-color: #fff'>At line:1 char:7</span>
<span style='color: #f00; background-color: #fff'>+ asdasda <span><</span><span><</span><span><</span><span><</span> </span>
PS> get-bufferhtml > out.html
PS> get-bufferhtml -palette print > out2.html
PS> get-bufferhtml -palette standard > out3.html
</pre>
<p>Clearly, fixed width fonts are best, but you can do whatever you like. I find that &#8220;Courier New&#8221; is best as the lines naturally line up without inter-line spacing.</p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/06/console-screen-grabs-in-html/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
	</channel>
</rss>

