<?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; Hint</title>
	<atom:link href="http://ps1.soapyfrog.com/category/hint/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>Cmdlet clashes</title>
		<link>http://ps1.soapyfrog.com/2007/03/06/cmdlet-clashes/</link>
		<comments>http://ps1.soapyfrog.com/2007/03/06/cmdlet-clashes/#comments</comments>
		<pubDate>Tue, 06 Mar 2007 09:56:22 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Cmdlets]]></category>
		<category><![CDATA[Grrr]]></category>
		<category><![CDATA[Hint]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Rant]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/03/06/cmdlet-clashes/</guid>
		<description><![CDATA[One of the things that struck me whilst developing Grrr as a snapin is: what do you do when you have a cmdlet with the same verb-noun pair as an existing cmdlet? If someone else had a cmdlet called, say, out-banner, and that cmdlet was already loaded in a snap-in (perhaps mandated by site policy), [...]]]></description>
			<content:encoded><![CDATA[<p>One of the things that struck me whilst developing <a href="/category/grrr/">Grrr</a> as a snapin is: what do you do when you have a cmdlet with the same verb-noun pair as an existing cmdlet?</p>
<p>If someone else had a cmdlet called, say, <code>out-banner</code>, and that cmdlet was already loaded in a snap-in (perhaps mandated by site policy), would I be able to register and add the Grrr snapin, which also defines it?</p>
<p>I&#8217;ve scanned the available documentation and the language grammar, used introspection in the shell and so on, but could not find anything to deal with this problem.</p>
<p>With projects like <a href="http://www.codeplex.com/PowerShellCX">PowerShell Community Extensions</a> seemingly laying claim to hundreds of common nouns and verbs, I was concerned that the scope for writing unique cmdlets would dry up real fast.</p>
<p><span id="more-62"></span></p>
<p>To determine what would happen, I <a href="/2007/02/26/grrr-11-and-big-invaders/">registered and added</a> <code>Soapyfrog.Grrr</code>, then wrote a new snapin, <code>Soapyfrog.Conflict</code>, with a single cmdlet, <code>out-banner</code>, conflicting with the one in Grrr.</p>
<p>I registered and added this, and was surprised that no warning of a conflict was given. To see if both were added, I tried this:</p>
<pre style='color: #000; background-color: #ccc; '>PS&gt; get-command out-banner

CommandType     Name                        Definition
-----------     ----                        ----------
Cmdlet          Out-Banner                  Out-Banner [-Text] <span>&lt;</span>Str...
Cmdlet          Out-Banner                  Out-Banner [-Text] <span>&lt;</span>Str...
</pre>
<p>Interesting. Both are available, so what happens when I try to invoke it?</p>
<pre style='color: #000; background-color: #ccc; '>PS&gt; out-banner hello
<span style='color: #800; background-color: #ccc'>The term &#39;out-banner&#39; resolved to a cmdlet name that is ambiguous. Pos</span>
<span style='color: #800; background-color: #ccc'>sible matches include: Soapyfrog.Grrr&#x5c;Out-Banner soapyfrog.conflict&#x5c;Ou</span>
<span style='color: #800; background-color: #ccc'>t-Banner.</span>
<span style='color: #800; background-color: #ccc'>At line:1 char:11</span>
<span style='color: #800; background-color: #ccc'>+ out-banner  <span>&lt;</span><span>&lt;</span><span>&lt;</span><span>&lt;</span> hello</span>
</pre>
<p>OK, so at this point, we know it&#8217;s possible to break existing PowerShell scripts by simply registering and adding a new snapin with a same-named cmdlet. Not good. Is there a work-around?</p>
<pre style='color: #000; background-color: #ccc; '>PS&gt; Soapyfrog.Grrr&#x5c;out-banner hello -fg &#39;o&#39;
o   o ooooo o     o      ooo
o   o o     o     o     o   o
ooooo ooo   o     o     o   o
o   o o     o     o     o   o
o   o ooooo ooooo ooooo  ooo
</pre>
<p>Yes! We can fully qualify the cmdlet name with the snapin name and a backslash.</p>
<p>So, it&#8217;s not as bad as I first feared, but as I noted above, you need to be very careful about how you code and run scripts in environments where you can&#8217;t predict what snapins are registered and installed.</p>
<p>I suppose you can create the correct shell environment with Export-Console and run your script with:  </p>
<p><code>powershell -psconsolefile xxx.psc1 -noprofile -command myscript.ps1</code></p>
<p>Or if your script requires a snapin, add the snapin in the script and fully qualify each cmdlet you use.</p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/03/06/cmdlet-clashes/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Debug and Verbose colouring</title>
		<link>http://ps1.soapyfrog.com/2007/01/29/debug-and-verbose-colouring/</link>
		<comments>http://ps1.soapyfrog.com/2007/01/29/debug-and-verbose-colouring/#comments</comments>
		<pubDate>Mon, 29 Jan 2007 17:59:05 +0000</pubDate>
		<dc:creator>adrian</dc:creator>
				<category><![CDATA[Hint]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://ps1.soapyfrog.com/2007/01/29/debug-and-verbose-colouring/</guid>
		<description><![CDATA[Over the weekend, I set about writing an IRC chat client/channel monitoring tool in PowerShell (more on that in a day or so) and one of the things I was doing a lot was writing verbose and debug information to the console. By default, Write-Verbose and Write-Debug cmdlets write nothing to the console, because the [...]]]></description>
			<content:encoded><![CDATA[<p>Over the weekend, I set about writing an IRC chat client/channel monitoring tool in PowerShell (more on that in a day or so) and one of the things I was doing a lot was writing verbose and debug information to the console.</p>
<p>By default, <code>Write-Verbose</code> and <code>Write-Debug</code> cmdlets write nothing to the console, because the the value of the variables <code>$VerbosePreference</code> and <code>$DebugPreference</code> respectively are &#8220;SilentlyContinue&#8221;.</p>
<p>If you set them both to &#8220;Continue&#8221; the text is written to the console, but both in bright yellow on black (I wonder why?), like this:</p>
<pre style='color: #eeedf0; background-color: #012456; '>PS&gt; $DebugPreference=&#34;continue&#34;
PS&gt; $VerbosePreference=&#34;continue&#34;
PS&gt; write-debug &#34;debug msg&#34;
<span style='color: #ff0; background-color: #000'>DEBUG: debug msg</span>
PS&gt; write-verbose &#34;verbose msg&#34;
<span style='color: #ff0; background-color: #000'>VERBOSE: verbose msg</span>
</pre>
<p>These colours can be changed so you can more easily distinguish between debug and verbose messages, and also not have the real output swamped.</p>
<p><span id="more-51"></span></p>
<p>The trick is to change the values of the colours in <code>$host.privatedata</code>, and   I do this:</p>
<pre>$defbg="darkmagenta"
$deffg="darkyellow"

# normal colours
$r=$host.ui.rawui
$r.BackgroundColor=$defbg
$r.foregroundColor=$deffg

$p=$host.privatedata
# error colours
$p.ErrorBackgroundColor=$defbg
$p.ErrorForegroundColor="red"

# warning colours
$p.WarningBackgroundColor=$defbg
$p.WarningForegroundColor="yellow"

# debug colours
$p.DebugBackgroundColor=$defbg
$p.DebugForegroundColor="darkgray"

# verbose colours
$p.VerboseBackgroundColor=$defbg
$p.VerboseForegroundColor="darkcyan"

# progress colours
$p.ProgressBackgroundColor="darkcyan"
$p.ProgressForegroundColor="yellow"
</pre>
<p>Now, the IRC app I&#8217;m working on, when I run with debug/verbose switched on, yields an output like this:</p>
<pre style='color: #eeedf0; background-color: #012456; font-family: "courier new"; font-size: 9pt; '>PS&gt; test
<span style='color: #888; background-color: #012456'>DEBUG: Using connection info:</span>
<span style='color: #888; background-color: #012456'>DEBUG: port: 6667</span>
<span style='color: #888; background-color: #012456'>DEBUG: nick: soapybot</span>
<span style='color: #888; background-color: #012456'>DEBUG: server: chat.freenode.net</span>
<span style='color: #888; background-color: #012456'>DEBUG: hostname: localhost</span>
<span style='color: #888; background-color: #012456'>DEBUG: user: soapybot</span>
<span style='color: #888; background-color: #012456'>DEBUG: realname: inout-irc as soapybot</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; NICK soapybot</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; USER soapybot localhost chat.freenode.net :inout-irc as soapybot</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> NOTICE AUTH :*** Looking up your hostname...</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> NOTICE AUTH :*** Found your hostname, welcome back</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> NOTICE AUTH :*** Checking ident</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> NOTICE AUTH :*** No identd (auth) response</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 001 soapybot :Welcome to the freenode IRC Network </span>
<span style='color: #088; background-color: #012456'>soapybot</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 002 soapybot :Your host is </span>
<span style='color: #088; background-color: #012456'>brown.freenode.net[brown.freenode.net/6667], running version hyperion-1.0.2b</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> NOTICE soapybot :*** Your host is </span>
<span style='color: #088; background-color: #012456'>brown.freenode.net[brown.freenode.net/6667], running version hyperion-1.0.2b</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 003 soapybot :This server was created Fri Dec 22 </span>
<span style='color: #088; background-color: #012456'>00:07:52 UTC 2006</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 004 soapybot brown.freenode.net hyperion-1.0.2b </span>
<span style='color: #088; background-color: #012456'>aAbBcCdDeEfFGhHiIjkKlLmMnNopPQrRsStTuUvVwWxXyYzZ01234569*@ bcdefFhiIklmnoPqstv</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 005 soapybot IRCD=dancer CAPAB CHANTYPES=# EXCEPTS INVEX</span>
<span style='color: #088; background-color: #012456'> CHANMODES=bdeIq,k,lfJD,cgijLmnPQrRstz CHANLIMIT=#:20 PREFIX=(ov)@+ MAXLIST=bdeI:50 </span>
<span style='color: #088; background-color: #012456'>MODES=4 STATUSMSG=@ KNOCK NICKLEN=16 :are supported by this server</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 005 soapybot SAFELIST CASEMAPPING=ascii CHANNELLEN=30 </span>
<span style='color: #088; background-color: #012456'>TOPICLEN=450 KICKLEN=450 KEYLEN=23 USERLEN=10 HOSTLEN=63 SILENCE=50 :are supported by </span>
<span style='color: #088; background-color: #012456'>this server</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 251 soapybot :There are 18601 listed and 16168 unlisted </span>
<span style='color: #088; background-color: #012456'>users on 24 servers</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 375 soapybot :- brown.freenode.net Message of the Day - </span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 372 soapybot :- Freenode is a service of Peer-Directed </span>
<span style='color: #088; background-color: #012456'>Projects Center, an</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 372 soapybot :- IRS 501(c)(3) not-for-profit </span>
<span style='color: #088; background-color: #012456'>organization.  Our yearly</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 372 soapybot :- fundraiser will begin soon; if you&#39;d </span>
<span style='color: #088; background-color: #012456'>like to donate early,</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 372 soapybot :- please see </span>
<span style='color: #088; background-color: #012456'>http://freenode.net/pdpc_donations.shtml for more</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 372 soapybot :- information.  Thank you for using </span>
<span style='color: #088; background-color: #012456'>freenode!</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 372 soapybot :- </span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 376 soapybot :End of /MOTD command.</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; JOIN #test,#test2,#archlinux</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :freenode-connect!freenode@freenode/bot/connect PRIVMSG soapybot :☺VERSION☺</span>
freenode-connect : soapybot : VERSION
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :soapybot!n=soapybot@*********** JOIN :#test</span>
<span style='color: #888; background-color: #012456'>DEBUG: We may have joined channel #test</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 332 soapybot #test :Welcome to #test - This channel is </span>
<span style='color: #088; background-color: #012456'>for testing only. Don&#39;t harass or annoy other users here. Don&#39;t paste senceless crap </span>
<span style='color: #088; background-color: #012456'>here. If you need a response for tests type &#39;#say foobar&#39; or &#39;#moo&#39; - Have a nice time </span>
<span style='color: #088; background-color: #012456'>in here... RIP lilo aka rob levin :&#39;(</span>
<span style='color: #888; background-color: #012456'>DEBUG: We have joined channel #test</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :soapybot!n=soapybot@*************** JOIN :#test2</span>
<span style='color: #888; background-color: #012456'>DEBUG: We may have joined channel #test2</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; PRIVMSG #test2 :hello</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :soapybot!n=soapybot@*************** JOIN :#archlinux</span>
<span style='color: #888; background-color: #012456'>DEBUG: We may have joined channel #archlinux</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :brown.freenode.net 332 soapybot #archlinux :[ Welcome to #archlinux! </span>
<span style='color: #088; background-color: #012456'>(!rules) || main: archlinux.org || forums: bbs.archlinux.org || wiki: wiki.archlinux.org</span>
<span style='color: #088; background-color: #012456'> || bugs: bugs.archlinux.org || AUR: aur.archlinux.org || iso: </span>
<span style='color: #088; background-color: #012456'>ftp://ftp.archlinux.org/other/0.8 ]</span>
<span style='color: #888; background-color: #012456'>DEBUG: We have joined channel #archlinux</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :schnappi!n=joy@debiancenter/user/schnappi PRIVMSG #test :Good after-noon, </span>
<span style='color: #088; background-color: #012456'>soapybot. It&#39;s 17:28h.GMT</span>
schnappi : #test : Good after-noon, soapybot. It&#39;s 17:28h.GMT
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> <img src='http://ps1.soapyfrog.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':D' class='wp-smiley' /> anny|!n=Danny@89-172-171-230.adsl.net.t-com.hr PART #archlinux :&#34;So Say We</span>
<span style='color: #088; background-color: #012456'> All.&#34;</span>
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :millinad!n=millinad@*************** PRIVMSG #test2 :hello </span>
<span style='color: #088; background-color: #012456'>soapybot</span>
millinad : #test2 : hello soapybot
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :millinad!n=millinad@*************** PRIVMSG #test2 :go now</span>
millinad : #test2 : go now
<span style='color: #088; background-color: #012456'>VERBOSE: <span>&lt;</span><span>&lt;</span> :millinad!n=millinad@*************** PRIVMSG #test2 :wibble</span>
millinad : #test2 : wibble
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; PART #test2</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; PART #archlinux</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; PART #test</span>
<span style='color: #088; background-color: #012456'>VERBOSE: &gt;&gt; QUIT :bye bye</span>
</pre>
<p>(some of the above has been trimmed for clarity and privacy).</p>
<p>The brighter white output is the normal output from the script, the grey is debug messages and cyan, verbose. It gives me all the output I want, without making it too hard to pick out the real information.</p>
<p>Once I&#8217;m happy that all is well, I can revert the <code>$VerbosePreference</code> and <code>$DebugPreference</code> variables back to &#8220;SilentlyContinue&#8221; and all you get is the default white output.</p>
]]></content:encoded>
			<wfw:commentRss>http://ps1.soapyfrog.com/2007/01/29/debug-and-verbose-colouring/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

