<?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>Get-PowerShell &#187; CTP 3</title>
	<atom:link href="http://get-powershell.com/category/ctp-3/feed/" rel="self" type="application/rss+xml" />
	<link>http://get-powershell.com</link>
	<description></description>
	<lastBuildDate>Sat, 10 Jul 2010 15:44:01 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Remoting Out of Memory Exception</title>
		<link>http://get-powershell.com/2009/03/16/remoting-out-of-memory-exception/</link>
		<comments>http://get-powershell.com/2009/03/16/remoting-out-of-memory-exception/#comments</comments>
		<pubDate>Mon, 16 Mar 2009 20:27:03 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[WSMAN]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2009/03/16/remoting-out-of-memory-exception/</guid>
		<description><![CDATA[A colleague of mine was using some remoting features in a dev lab and came across an interesting issue. He was using some native commands to build out a SharePoint environment. One of the commands he was using kept throwing a OutOfMemory Exception error. The system had plenty of memory available, so it was definitely [...]]]></description>
			<content:encoded><![CDATA[<p>A colleague of mine was using some remoting features in a dev lab and came across an interesting issue. He was using some native commands to build out a SharePoint environment. One of the commands he was using kept throwing a OutOfMemory Exception error. The system had plenty of memory available, so it was definitely an issue with the remoting client. Poking around in the WSMAN: Provider we found a config option called MaxMemoryPerShellMB in WSMAN:\localhost\Shell\</p>
<p>The default value is 150, which seems well and good for most commands. However, this is the second time I have run into it with different commands so I think it is worth noting. After upping the config to 512, all was right with the world again.</p>
<p>set-item wsman:localhost\Shell\MaxMemoryPerShellMB 512
<p>I have to say i love the new WSMAN: provider. It makes something that was incredibly difficult to manipulate a snap.
<p>Hope that helps,
<p>Andy</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2009/03/16/remoting-out-of-memory-exception/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using a Color Dialog to choose colors for ISE</title>
		<link>http://get-powershell.com/2009/01/29/using-a-color-dialog-to-choose-colors-for-ise/</link>
		<comments>http://get-powershell.com/2009/01/29/using-a-color-dialog-to-choose-colors-for-ise/#comments</comments>
		<pubDate>Thu, 29 Jan 2009 04:35:13 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[ISE]]></category>
		<category><![CDATA[Integrated Scripting Environment]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2009/01/29/using-a-color-dialog-to-choose-colors-for-ise/</guid>
		<description><![CDATA[Currently, there are no default UI options to set the color for the Script Pane, the Command Pane, or the Output Pane. However, these can all be changed using $psISE. I wrote a few functions to help with this. function Set-CommandBackPaneColor { param ( [parameter(Mandatory=$true,ValueFromPipeline=$true)] $color ) $psise.Options.CommandPaneBackground = $color } function Set-OutputPaneColor { param [...]]]></description>
			<content:encoded><![CDATA[<p align="left"><a href="http://get-powershell.com/wp-content/uploads/2009/01/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://get-powershell.com/wp-content/uploads/2009/01/image-thumb1.png" width="475" height="287" /></a> </p>
<p align="left">Currently, there are no default UI options to set the color for the Script Pane, the Command Pane, or the Output Pane. However, these can all be changed using $psISE.</p>
<p align="left">I wrote a few functions to help with this.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" class="CodeByDougFinke">function Set-CommandBackPaneColor {
param
(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $color
)
    $psise.Options.CommandPaneBackground = $color
}

function Set-OutputPaneColor {
param
(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $color
)
    $psise.Options.OutputPaneBackground = $color
    $psise.Options.OutputPaneTextBackground = $color
}

function Set-ScriptPaneColor {
param
(
    [parameter(Mandatory=$true,ValueFromPipeline=$true)]
    $color
)
    $psise.Options.ScriptPaneBackground = $color
}
</pre>
</div>
<p style="font-size: xx-small">Automatically generated with a <i>custom version</i> of <a href="http://blogs.msdn.com/powershell/archive/tags/Write-CommandBlogPost/default.aspx">Write-CommandBlogPost</a></p>
<p align="left">Set-OutputPaneColor sets two options, OutputPaneBackground and OutputPaneTextBackground. I have found that I like to have these the same, but you can easily separate them out if you like.</p>
<p align="left">The last little tidbit is figuring out how to get a color picker rather than typing in the name of the color. We can accomplish this with a little Winforms action.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px" class="CodeByDougFinke">function Get-Color {
    $colorDialog = new-object System.Windows.Forms.ColorDialog
    $colorDialog.AllowFullOpen = $false
    [void]$colorDialog.ShowDialog()
    $colorDialog.Color.Name
}
</pre>
</div>
<p style="font-size: xx-small">Automatically generated with a <i>custom version</i> of <a href="http://blogs.msdn.com/powershell/archive/tags/Write-CommandBlogPost/default.aspx">Write-CommandBlogPost</a></p>
</p>
<p>This will return the name of the color that was picked</p>
<p><a href="http://get-powershell.com/wp-content/uploads/2009/01/image1.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://get-powershell.com/wp-content/uploads/2009/01/image-thumb1.png" width="475" height="287" /></a> </p>
<p>After clicking on Red, I get the following output</p>
<p><a href="http://get-powershell.com/wp-content/uploads/2009/01/image2.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://get-powershell.com/wp-content/uploads/2009/01/image-thumb2.png" width="320" height="117" /></a></p>
<p>So now we can tie this all together with one final line to add a custom menu to ISE</p>
<p>[void]$psISE.CustomMenu.Submenus.Add(&quot;Output Pane Color&quot;, {Get-Color | Set-OutputPaneColor},$null)</p>
<p>I just passed in Null because I didn’t want a keyboard shortcut, but you can use one pretty easily.</p>
<p>So now I get the following:</p>
<p><a href="http://get-powershell.com/wp-content/uploads/2009/01/image3.png"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://get-powershell.com/wp-content/uploads/2009/01/image-thumb3.png" width="480" height="280" /></a> </p>
<p>I could set up Menus to set other color options for the script and command panes as well, but I figure that is enough screenshots to make the point.</p>
<p>The <a href="http://karlprosser.com/coder/2009/01/03/powershell-analayzer-like-execution-hotkeys-for-ps-ctp3-ise/">other custom commands</a> are from <a href="http://karlprosser.com/coder/about/">Karl Prosser</a>. I highly recommend you take a look at them as well. Very useful.</p>
<p>So there is one (not so subtle) flaw in the get-color function. It does not always place the color dialog on the top, so sometimes I have to Alt-Tab over to it. There is probably some nifty way with winforms to make it show up on top all the time, but I figured I would get this out there and then work on that little part.</p>
<p>Secondly, not all the colors work right now.</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2009/01/29/using-a-color-dialog-to-choose-colors-for-ise/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>PowerShell Remoting on Windows 2008 R2 Server Core</title>
		<link>http://get-powershell.com/2009/01/14/powershell-remoting-on-windows-2008-r2-server-core/</link>
		<comments>http://get-powershell.com/2009/01/14/powershell-remoting-on-windows-2008-r2-server-core/#comments</comments>
		<pubDate>Wed, 14 Jan 2009 15:25:28 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Remoting]]></category>
		<category><![CDATA[Server Core]]></category>
		<category><![CDATA[Windows 2008 R2]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2009/01/14/powershell-remoting-on-windows-2008-r2-server-core/</guid>
		<description><![CDATA[I&#8217;ve been working on building out some 2008 R2 Core servers the last couple days and of course I wanted to get PowerShell up and running on them.&#160; First of all, to install the PowerShell feature you need to run this command start /w ocsetup MicrosoftWindowsPowerShell Note that ocsetup is case sensitive and you need [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been working on building out some 2008 R2 Core servers the last couple days and of course I wanted to get PowerShell up and running on them.&nbsp; First of all, to install the PowerShell feature you need to run this command</p>
<p>start /w ocsetup MicrosoftWindowsPowerShell</p>
<p>Note that ocsetup is case sensitive and you need to get the name of the feature and/or role exactly right.</p>
<p>Once you get the feature installed, you can launch powershell from the cmd prompt by using the full path to c:\windows\system32\windowspowershell\v1.0\powershell.exe.</p>
<p>Now that we have PowerShell V2 running, we can get-started with Remoting. To enable V2 remoting, there is a built-function called Enable-PSRemoting which typically is all you need. However, there is a known issue with Windows 7 Beta x64 systems where WOW components are not installed &#8211; a category which server core falls into.</p>
<p>If you try to enable remoting, you will get an error about a corrupted plugin in WSMAN.</p>
<p>To work around this, you need to remote a registry value. Run the following command </p>
<p>remove-item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\WSMAN\Plugin\Microsoft.PowerShell32
<p>After that, you can run Enable-PSRemoting and you are good to go.</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2009/01/14/powershell-remoting-on-windows-2008-r2-server-core/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Advanced Functions Support -confirm</title>
		<link>http://get-powershell.com/2009/01/06/advanced-functions-support-confirm/</link>
		<comments>http://get-powershell.com/2009/01/06/advanced-functions-support-confirm/#comments</comments>
		<pubDate>Tue, 06 Jan 2009 05:44:02 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[Advanced Function]]></category>
		<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/?p=170</guid>
		<description><![CDATA[I was using the &#8220;Module&#8221; Module to generate some scripts and started looking at SupportsShouldProcess , a parameter the CmdletBinding attribute. Turns out with V2 it is very simple to implement some sanity checking in the functions we write so people don&#8217;t go and blow their pinky tow off with a shotgun. So the trick [...]]]></description>
			<content:encoded><![CDATA[<p>I was using the &#8220;Module&#8221; Module to generate some scripts and started looking at SupportsShouldProcess , a parameter the CmdletBinding attribute.</p>
<p>Turns out with V2 it is very simple to implement some sanity checking in the functions we write so people don&#8217;t go and blow their pinky tow off with a shotgun. So the trick is a simple IF statement in the PROCESS Block of your script or function.</p>
<p>There is a variable called $PSCmdlet that you can use to determine if the user entered the -confirm or -whatif switch. The first parameter in the ShouldProcess method is the target and the second parameter is the operation. Note that if the operation is not specified, it will default to the name of the function.</p>
<blockquote><p><img class="alignnone size-full wp-image-173" title="supportshouldprocessfunction" src="http://get-powershell.com/wp-content/uploads/2009/01/supportshouldprocessfunction.png" alt="supportshouldprocessfunction" width="638" height="576" /></p></blockquote>
<p>Here I have a parameter called $test and if I type -confirm it will ask me if I want to &#8220;Destroy Everything&#8221; on target &#8220;Whatever the value of $test is&#8221;</p>
<p>The ISE gives a nice Windows dialog box with the options when I type &#8220;Get-Something &#8220;That you can see&#8221; -confirm</p>
<p><img class="aligncenter size-full wp-image-174" title="confirmdestroytheworld" src="http://get-powershell.com/wp-content/uploads/2009/01/confirmdestroytheworld.png" alt="confirmdestroytheworld" width="405" height="116" /></p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2009/01/06/advanced-functions-support-confirm/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Using Proxy Commands in PowerShell</title>
		<link>http://get-powershell.com/2009/01/04/using-proxy-commands-in-powershell/</link>
		<comments>http://get-powershell.com/2009/01/04/using-proxy-commands-in-powershell/#comments</comments>
		<pubDate>Sun, 04 Jan 2009 22:44:57 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[Powershell]]></category>
		<category><![CDATA[Proxy Commands]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2009/01/04/using-proxy-commands-in-powershell/</guid>
		<description><![CDATA[Jeffrey Snover just posted a great article on how to use Proxy Commands in CTP3. He also built a module called MetaProgramming that makes this much easier. I was able to take what he did and created a proxy command for get-childitem and added two switch parameters, -containersOnly and -NoContainersOnly. I posted the code up [...]]]></description>
			<content:encoded><![CDATA[<p>Jeffrey Snover just posted <a href="http://blogs.msdn.com/powershell/archive/2009/01/04/extending-and-or-modifing-commands-with-proxies.aspx">a great article on how to use Proxy Commands in CTP3</a>. He also built a module called MetaProgramming that makes this much easier. I was able to take what he did and created a proxy command for get-childitem and added two switch parameters, -containersOnly and -NoContainersOnly.</p>
<p>I posted the code up on PoshCode <a href="http://poshcode.org/785">here</a>.</p>
<p> <script src="http://PoshCode.org/embed/785" type="text/javascript"></script>
<div class="poshcode code posh">
<style type="text/css">.posh li.li2, .posh li.li1 { list-style-type:decimal-leading-zero; white-space:nowrap;}.syntax .posh { overflow: auto; background-color:#eaeaea; border:1px solid #dddddd; border-width: 1px 1px 0px 1px;}.syntax .poshcredit {background-color:#eaeaea;border-bottom:1px solid #dddddd;color:#666666;font-size:85%;overflow:hidden;padding:0.5em 1em;}/* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */.posh .de1, .posh .de2 {font-family: 'Courier New', courier, monospace; font-weight: normal;}.posh  {font-family: monospace;}.posh .imp {font-weight: bold; color: red;}.posh li {background: #ffffff;}.posh li.li2 {background: #f8f8f8;}.posh .kw1 {color: #666699; font-weight: bold;}.posh .kw2 {color: #333399; font-weight: bold; font-style: italic;}.posh .kw3 {color: #003366; font-weight: bold;}.posh .kw4 {color: #660033;}.posh .co1 {color: #666666; font-style: italic;}.posh .comulti {color: #666666; font-style: italic;}.posh .es0 {color: #000099; font-weight: bold;}.posh .br0 {color: #66cc66;}.posh .st0 {color: #009900;}.posh .nu0 {color: #cc66cc;}.posh .me1 {color: #003366;}.posh .me2 {color: #003366;}.posh .re0 {color: #0066cc; font-style: italic;}.posh .re1 {font-style: normal;}.posh .re2 {color: #000066;}.posh .re3 {color: #660033; font-weight: bold;}.posh .re4 {color: #003366; font-weight: bold;}</style>
<div class="syntax">
<div class="posh" style="font-family: monospace">
<ol>
<li class="li1">
<div class="de1"><span class="kw1">Function</span> <span class="re0">Get-<span class="re1">ChildItemProxy</span></span> <span class="br0">{</span></div>
<li class="li2">
<div class="de2"><span class="br0">[</span>CmdletBinding<span class="br0">(</span>DefaultParameterSetName=<span class="st0">'Items'</span>, SupportsTransactions=<span class="re3">$true</span><span class="br0">)</span><span class="br0">]</span></div>
<li class="li1">
<div class="de1"><span class="kw1">param</span><span class="br0">(</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="br0">[</span>Parameter<span class="br0">(</span>ParameterSetName=<span class="st0">'Items'</span>, Position=<span class="nu0">0</span>, ValueFromPipeline=<span class="re3">$true</span>, ValueFromPipelineByPropertyName=<span class="re3">$true</span><span class="br0">)</span><span class="br0">]</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw3">System</span>.<span class="kw3">String</span><span class="br0">[</span><span class="br0">]</span><span class="br0">]</span></span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>Path<span class="br0">}</span>,</div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="br0">[</span>Parameter<span class="br0">(</span>ParameterSetName=<span class="st0">'LiteralItems'</span>, Mandatory=<span class="re3">$true</span>, Position=<span class="nu0">0</span>, ValueFromPipelineByPropertyName=<span class="re3">$true</span><span class="br0">)</span><span class="br0">]</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">[</span>Alias<span class="br0">(</span><span class="st0">'PSPath'</span><span class="br0">)</span><span class="br0">]</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw3">System</span>.<span class="kw3">String</span><span class="br0">[</span><span class="br0">]</span><span class="br0">]</span></span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>LiteralPath<span class="br0">}</span>,</div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">[</span>Parameter<span class="br0">(</span>Position=<span class="nu0">1</span><span class="br0">)</span><span class="br0">]</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw3">System</span>.<span class="kw3">String</span><span class="br0">]</span></span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span><span class="kw1">Filter</span><span class="br0">}</span>,</div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw3">System</span>.<span class="kw3">String</span><span class="br0">[</span><span class="br0">]</span><span class="br0">]</span></span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>Include<span class="br0">}</span>,</div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw3">System</span>.<span class="kw3">String</span><span class="br0">[</span><span class="br0">]</span><span class="br0">]</span></span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>Exclude<span class="br0">}</span>,</div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw1">Switch</span><span class="br0">]</span></span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>Recurse<span class="br0">}</span>,</div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw1">Switch</span><span class="br0">]</span></span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>Force<span class="br0">}</span>,</div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw1">Switch</span><span class="br0">]</span></span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>Name<span class="br0">}</span>,</div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; </div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw1">Switch</span><span class="br0">]</span></span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>ContainersOnly<span class="br0">}</span>,</div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; </div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span><span class="kw1">Switch</span><span class="br0">]</span></span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; $<span class="br0">{</span>NoContainersOnly<span class="br0">}</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1"><span class="kw1">begin</span></div>
<li class="li2">
<div class="de2"><span class="br0">{</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="kw1">try</span> <span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$outBuffer</span> = <span class="re3">$null</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="kw1">if</span> <span class="br0">(</span><span class="re3">$PSBoundParameters</span>.<span class="me1">TryGetValue</span><span class="br0">(</span><span class="st0">&#8216;OutBuffer&#8217;</span>, <span class="re4"><span class="br0">[</span><span class="kw3">ref</span><span class="br0">]</span></span><span class="re3">$outBuffer</span><span class="br0">)</span> <span class="re2">-and</span> <span class="re3">$outBuffer</span> <span class="re2">-gt</span> <span class="nu0">1024</span><span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">{</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$PSBoundParameters</span><span class="br0">[</span><span class="st0">'OutBuffer'</span><span class="br0">]</span> = <span class="nu0">1024</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">}</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$wrappedCmd</span> = <span class="re3">$ExecutionContext</span>.<span class="me1">InvokeCommand</span>.<span class="me1">GetCommand</span><span class="br0">(</span><span class="st0">&#8216;Get-ChildItem&#8217;</span>, <span class="re4"><span class="br0">[</span><span class="kw3">System</span>.<span class="me1">Management</span>.<span class="me1">Automation</span>.<span class="me1">CommandTypes</span><span class="br0">]</span></span>::<span class="me2">Cmdlet</span><span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="kw1">if</span> <span class="br0">(</span><span class="re3">$ContainersOnly</span><span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">{</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span>Void<span class="br0">]</span></span><span class="re3">$PSBoundParameters</span>.<span class="me1">Remove</span><span class="br0">(</span><span class="st0">&#8220;ContainersOnly&#8221;</span><span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$scriptCmd</span> = <span class="br0">{</span>&amp; <span class="re3">$wrappedCmd</span> @PSBoundParameters | <span class="re0">Where-<span class="re1">Object</span></span> <span class="br0">{</span><span class="re3">$_</span>.<span class="me1">PSIsContainer</span> <span class="re2">-eq</span> <span class="re3">$true</span><span class="br0">}</span><span class="br0">}</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">}</span> <span class="kw1">elseif</span> <span class="br0">(</span><span class="re3">$NoContainersOnly</span><span class="br0">)</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re4"><span class="br0">[</span>Void<span class="br0">]</span></span><span class="re3">$PSBoundParameters</span>.<span class="me1">Remove</span><span class="br0">(</span><span class="st0">&#8220;NoContainersOnly&#8221;</span><span class="br0">)</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$scriptCmd</span> = <span class="br0">{</span>&amp; <span class="re3">$wrappedCmd</span> @PSBoundParameters | <span class="re0">Where-<span class="re1">Object</span></span> <span class="br0">{</span><span class="re3">$_</span>.<span class="me1">PSIsContainer</span> <span class="re2">-eq</span> <span class="re3">$false</span><span class="br0">}</span><span class="br0">}</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">}</span>&nbsp;&nbsp;&nbsp; </div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$scriptCmd</span> = <span class="br0">{</span>&amp; <span class="re3">$wrappedCmd</span> @PSBoundParameters <span class="br0">}</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="br0">}</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$steppablePipeline</span> = <span class="re3">$scriptCmd</span>.<span class="me1">GetSteppablePipeline</span><span class="br0">(</span><span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$steppablePipeline</span>.<span class="kw1">Begin</span><span class="br0">(</span><span class="re3">$PSCmdlet</span><span class="br0">)</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">}</span> <span class="kw1">catch</span> <span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="kw1">throw</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">}</span></div>
<li class="li2">
<div class="de2"><span class="br0">}</span></div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2"><span class="kw1">process</span></div>
<li class="li1">
<div class="de1"><span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="kw1">try</span> <span class="br0">{</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$steppablePipeline</span>.<span class="kw1">Process</span><span class="br0">(</span><span class="re3">$_</span><span class="br0">)</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="br0">}</span> <span class="kw1">catch</span> <span class="br0">{</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="kw1">throw</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp; <span class="br0">}</span></div>
<li class="li1">
<div class="de1"><span class="br0">}</span></div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1"><span class="kw1">end</span></div>
<li class="li2">
<div class="de2"><span class="br0">{</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="kw1">try</span> <span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="re3">$steppablePipeline</span>.<span class="kw1">End</span><span class="br0">(</span><span class="br0">)</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">}</span> <span class="kw1">catch</span> <span class="br0">{</span></div>
<li class="li2">
<div class="de2">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span class="kw1">throw</span></div>
<li class="li1">
<div class="de1">&nbsp;&nbsp;&nbsp; <span class="br0">}</span></div>
<li class="li2">
<div class="de2"><span class="br0">}</span></div>
<li class="li1">
<div class="de1">&amp;<span class="kw2">lt</span>;<span class="co1">#</span></div>
<li class="li2">
<div class="de2">&nbsp;</div>
<li class="li1">
<div class="de1">.<span class="me1">ForwardHelpTargetName</span> <span class="re0">Get-<span class="re1">ChildItem</span></span></div>
<li class="li2">
<div class="de2">.<span class="me1">ForwardHelpCategory</span> Cmdlet</div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2"><span class="co1">#&gt;</span></div>
<li class="li1">
<div class="de1">&nbsp;</div>
<li class="li2">
<div class="de2"><span class="br0">}</span> </div>
</li>
</ol>
</div>
<div class="poshcredit"><a title="download file" style="float: right" href="http://poshcode.org/get/785">download</a><a title="full view" href="http://poshcode.org/?show=785">This Script</a> brought to you by <a href="http://PoshCode.org">PoshCode</a></div>
</div>
</div>
<div class="poshcode code posh">
<style type="text/css">.posh li.li2, .posh li.li1 { list-style-type:decimal-leading-zero; white-space:nowrap;}.syntax .posh { overflow: auto; background-color:#eaeaea; border:1px solid #dddddd; border-width: 1px 1px 0px 1px;}.syntax .poshcredit {background-color:#eaeaea;border-bottom:1px solid #dddddd;color:#666666;font-size:85%;overflow:hidden;padding:0.5em 1em;}/* GeSHi (c) Nigel McNie 2004 (http://qbnz.com/highlighter) */.posh .de1, .posh .de2 {font-family: 'Courier New', courier, monospace; font-weight: normal;}.posh  {font-family: monospace;}.posh .imp {font-weight: bold; color: red;}.posh li {background: #ffffff;}.posh li.li2 {background: #f8f8f8;}.posh .kw1 {color: #666699; font-weight: bold;}.posh .kw2 {color: #333399; font-weight: bold; font-style: italic;}.posh .kw3 {color: #003366; font-weight: bold;}.posh .kw4 {color: #660033;}.posh .co1 {color: #666666; font-style: italic;}.posh .comulti {color: #666666; font-style: italic;}.posh .es0 {color: #000099; font-weight: bold;}.posh .br0 {color: #66cc66;}.posh .st0 {color: #009900;}.posh .nu0 {color: #cc66cc;}.posh .me1 {color: #003366;}.posh .me2 {color: #003366;}.posh .re0 {color: #0066cc; font-style: italic;}.posh .re1 {font-style: normal;}.posh .re2 {color: #000066;}.posh .re3 {color: #660033; font-weight: bold;}.posh .re4 {color: #003366; font-weight: bold;}</style>
<div class="syntax">&nbsp;</div>
</div>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2009/01/04/using-proxy-commands-in-powershell/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Inline F# in PowerShell</title>
		<link>http://get-powershell.com/2008/12/30/inline-f-in-powershell/</link>
		<comments>http://get-powershell.com/2008/12/30/inline-f-in-powershell/#comments</comments>
		<pubDate>Tue, 30 Dec 2008 22:59:20 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Add-Type]]></category>
		<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[F#]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2008/12/30/inline-f-in-powershell/</guid>
		<description><![CDATA[We can use C#&#160; quite easily with the Add-Type Cmdlet. With the -language parameter, you can also use VB .NET. However,if you are into functional programming and like F#, you can use that as well, although not quite as easily. First, go and download the September 2008 CTP of F#. Once you have this installed, [...]]]></description>
			<content:encoded><![CDATA[<p>We can use C#&nbsp; quite easily with the Add-Type Cmdlet. With the -language parameter, you can also use VB .NET. However,if you are into <a href="http://en.wikipedia.org/wiki/Functional_programming">functional programming</a> and like <a href="http://research.microsoft.com/en-us/um/people/curtisvv/fsharp_default.aspx">F#</a>, you can use that as well, although not quite as easily. </p>
<p>First, go and download the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=61ad6924-93ad-48dc-8c67-60f7e7803d3c&amp;displaylang=en">September 2008 CTP of F#</a>. Once you have this installed, launch the 32 bit version of PowerShell. I&#8217;m using a 64 bit Vista machine and I had problems with the 64 bit version of Powershell with one line which I will get to in a bit. I think it has to do with the F# CodeDom Provider, not with PowerShell itself.</p>
<p>The F# CodeDom.dll was installed in C:\Program Files (x86)\FSharp-1.9.2.9\bin for me. Your mileage may vary. Anyway, cd into the bin directory of F# and you will find a file called FSharp.Compiler.CodeDom.dll. Once you are there, you can run the following lines to load up the F# Code Provider.</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, 'Courier New', courier, monospace; background-color: #f4f4f4">
<pre style="padding-right: 0px; padding-left: 0px; font-size: 8pt; padding-bottom: 0px; margin: 0em; overflow: visible; width: 100%; color: black; border-top-style: none; line-height: 12pt; padding-top: 0px; font-family: consolas, 'Courier New', courier, monospace; border-right-style: none; border-left-style: none; background-color: #f4f4f4; border-bottom-style: none">Add-Type -Path FSharp.Compiler.CodeDom.dll
$provider = New-Object Microsoft.FSharp.Compiler.CodeDom.FSharpCodeProvider
$fsharpCode = <span style="color: #006080">@"
let sample = [1;2;3;4;5;6;7]
"</span>@
$fsharpType = Add-Type -TypeDefinition $fSharpCode -CodeDomProvider $provider -PassThru |
where { $_.IsPublic }
$fsharpType::sample</pre>
</div>
<p>When you call Sample on $fsharpType, it will return the array with numbers 1 through 7.</p>
<p>For some reason when I ran this on a 64 bit I get the following error when I try to add the type with typeDefinition $fsharpCode on line 6</p>
<p><font color="#ff0000">Add-Type : The system cannot find the file specified<br />At line:6 char:23<br />+ $fsharpType = Add-Type &lt;&lt;&lt;&lt;&nbsp; -TypeDefinition $fSharpCode -CodeDomProvider $provider -PassThru | where { $_.IsPublic }<br />&nbsp;&nbsp;&nbsp; + CategoryInfo&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; : NotSpecified: (:) [Add-Type], Win32Exception<br />&nbsp;&nbsp;&nbsp; + FullyQualifiedErrorId : System.ComponentModel.Win32Exception,Microsoft.PowerShell.Commands.AddTypeCommand</font></p>
<p>If you are into this sort of thing, have fun!</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2008/12/30/inline-f-in-powershell/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>ISE  &#8211; Comment out a block of text</title>
		<link>http://get-powershell.com/2008/12/29/ise-comment-out-a-block-of-text/</link>
		<comments>http://get-powershell.com/2008/12/29/ise-comment-out-a-block-of-text/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 01:14:22 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[Integrated Scripting Environment]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2008/12/29/ise-comment-out-a-block-of-text/</guid>
		<description><![CDATA[In a comment in an earlier post, reader Bernd asks the following question: Now I&#8217;m guessing if there is a way to use $psise.CustomMenu to add CommentBlock and UnCommentBlock commands. One way to tackle this would be the following. $text = $psise.CurrentOpenedFile.editor.SelectedText $psise.CurrentOpenedFile.editor.InsertText(&#34;&#60;# $text #&#62;&#34;) Once you have this you can wrap it in a [...]]]></description>
			<content:encoded><![CDATA[<p>In a <a href="http://get-powershell.com/2008/12/18/customizing-graphical-powershellise/">comment in an earlier post</a>, reader Bernd asks the following question:</p>
<p>Now I&#8217;m guessing if there is a way to use $psise.CustomMenu to add CommentBlock and UnCommentBlock commands.</p>
<p>One way to tackle this would be the following. </p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">$text = $psise.CurrentOpenedFile.editor.SelectedText
$psise.CurrentOpenedFile.editor.InsertText(<span style="color: #006080">&quot;&lt;# $text #&gt;&quot;</span>)      </pre>
</div>
<p>Once you have this you can wrap it in a function and use <a href="http://get-powershell.com/2008/12/28/more-integrated-scripting-environment-customization/">Custom Menus</a> to create a “Comment Block” Menu item.</p>
<p>Hope this helps.</p>
<p>Andy</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2008/12/29/ise-comment-out-a-block-of-text/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Code Snippets in PowerShell ISE</title>
		<link>http://get-powershell.com/2008/12/29/code-snippets-in-powershell-ise/</link>
		<comments>http://get-powershell.com/2008/12/29/code-snippets-in-powershell-ise/#comments</comments>
		<pubDate>Mon, 29 Dec 2008 00:31:22 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[ISE]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2008/12/29/code-snippets-in-powershell-ise/</guid>
		<description><![CDATA[Granted, PowerShell doesn’t always come with all the features you need right out of the box. However, because we have the power of .NET and an awesome scripting language, we can pretty much do whatever we need to do and we don’t have to wait for the PS team to ship V-Next. The PowerShell team [...]]]></description>
			<content:encoded><![CDATA[<p>Granted, PowerShell doesn’t always come with all the features you need right out of the box. However, because we have the power of .NET and an awesome scripting language, we can pretty much do whatever we need to do and we don’t have to wait for the PS team to ship V-Next. </p>
<p>The PowerShell team has taken this philosophy into the development of the ISE as well. In a couple previous posts <a href="http://get-powershell.com/2008/12/28/more-integrated-scripting-environment-customization/">here</a> and <a href="http://get-powershell.com/2008/12/18/customizing-graphical-powershellise/">here</a>, I have talked about some very basic customizations using the $PSISE variable that comes with the Scripting Integrated Environment.</p>
<p>One thing I love about PS V2 is Advanced Functions. The only bummer is there is a lot of boilerplate text for each one. This sounds like a perfect opportunity for a code snippet. We can add some functions to our $PROFILE in the PowerShell ISE to make this happen.</p>
<p>First of all, we need to open our $profile script. It probably doesn’t exist so you can do the following. Note that the ISE is a PS host and it has its own profile, different than the one for PowerShell.exe that you use in Console.Exe.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">new-item -type file -force $profile</pre>
</p></div>
</div>
<p>Now we can open it in the ISE with the following line</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">$psise.CurrentOpenedRunspace.OpenedFiles.Add($profile) </pre>
</p></div>
</div>
<p>Now that we have the $profile open, we can create a function that will insert some text into the file that is currently being edited.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">function</span> Insert-Text
{
<span style="color: #0000ff">param</span>(
    [parameter(Mandatory=$true, ValueFromPipeline=$true]
    [string]
    $text
    )
$currentFilePath = $psise.CurrentOpenedFile.FullPath
$currentFile = $psIse.CurrentOpenedRunspace.OpenedFiles |
               where {$_.FullPath <span style="color: #cc6633">-eq</span> $currentFilePath}
$currentFile.editor.InsertText($text)
}</pre>
</div>
<p>This function will insert text into the current script at the cursor’s location.</p>
<p>Now we need to write the actual snippet, which can also be a function</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #0000ff">function</span> New-FunctionTemplate
{
$f = <span style="color: #006080">@&quot;
function Verb-Noun {
param (
    [parameter(Mandatory=$true, ValueFromPipeline=$true)
    [string]
    $p1
)
begin {}
process {}
end {}
}
&quot;</span>@
Insert-Text -text $f
}</pre>
</div>
<p>The last line uses the Insert-Text function that we just created and inserts the snippet that is stored in the HereString $f. </p>
<p>Now we need to put it together and create a shortcut key and a new custom menu to insert this text.</p>
<div>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">$psIse.CustomMenu.Submenus.Add(<span style="color: #006080">&quot;_Function Template&quot;</span>, {New-FunctionTemplate}, <span style="color: #006080">&quot;Alt+F&quot;</span>)</pre>
</div>
<p>For this particular instance, I chose the name New FunctionTemplate and used Alt F for the keyboard shortcut.</p>
<p><a href="http://get-powershell.com/wp-content/uploads/2008/12/functiontemplate.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="FunctionTemplate" border="0" alt="FunctionTemplate" src="http://get-powershell.com/wp-content/uploads/2008/12/functiontemplate-thumb.jpg" width="489" height="255" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2008/12/29/code-snippets-in-powershell-ise/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>More Integrated Scripting Environment Customization</title>
		<link>http://get-powershell.com/2008/12/28/more-integrated-scripting-environment-customization/</link>
		<comments>http://get-powershell.com/2008/12/28/more-integrated-scripting-environment-customization/#comments</comments>
		<pubDate>Sun, 28 Dec 2008 22:26:57 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[ISE]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2008/12/28/more-integrated-scripting-environment-customization/</guid>
		<description><![CDATA[You can add custom menus using $PSISE in the PowerShell Integrated Scripting Environment. Quite simply, you create a custom menu, assign it a scriptblock, and a keyboard shortcut. For example, lets say you wanted Ctrl-D to always run the dir (get-childitem) command. You can use the CustomMenu class like so. 1: $psIse.CustomMenu.Submenus.Add(&#34;_Dir&#34;, {dir}, &#34;Ctrl+D&#34;) In [...]]]></description>
			<content:encoded><![CDATA[<p>You can add custom menus using $PSISE in the PowerShell Integrated Scripting Environment. Quite simply, you create a custom menu, assign it a scriptblock, and a keyboard shortcut. For example, lets say you wanted Ctrl-D to always run the dir (get-childitem) command. </p>
<p>You can use the CustomMenu class like so.</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> $psIse.CustomMenu.Submenus.Add(<span style="color: #006080">&quot;_Dir&quot;</span>, {dir}, <span style="color: #006080">&quot;Ctrl+D&quot;</span>)</pre>
</p></div>
</div>
<p>In addition to the keyboard shortcut, you also get a menu as well.</p>
<p><a href="http://get-powershell.com/wp-content/uploads/2008/12/custommenu.jpg"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="CustomMenu" border="0" alt="CustomMenu" src="http://get-powershell.com/wp-content/uploads/2008/12/custommenu-thumb.jpg" width="477" height="132" /></a> </p>
<p>Now when you hit Ctrl-D, it will run the dir command. All kinds of cool things are available within the editor with the new object model. </p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2008/12/28/more-integrated-scripting-environment-customization/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Industrial Strength Functions in V2 Part 2</title>
		<link>http://get-powershell.com/2008/12/23/industrial-strength-functions-in-v2-part-2/</link>
		<comments>http://get-powershell.com/2008/12/23/industrial-strength-functions-in-v2-part-2/#comments</comments>
		<pubDate>Tue, 23 Dec 2008 18:01:08 +0000</pubDate>
		<dc:creator>Andy Schneider</dc:creator>
				<category><![CDATA[CTP 3]]></category>
		<category><![CDATA[Function]]></category>
		<category><![CDATA[Powershell]]></category>

		<guid isPermaLink="false">http://get-powershell.com/2008/12/23/industrial-strength-functions-in-v2-part-2/</guid>
		<description><![CDATA[Jeffrey Snover just published a great article on using the&#160; capabilities of Advanced Functions. They have changed the name from Script Cmdlets to Advanced Functions and completely gotten rid of the Cmdlet keyword. This actually makes a lot of sense IMHO. One of the beauties of this is that there is a smooth path from [...]]]></description>
			<content:encoded><![CDATA[<p>Jeffrey Snover just published a <a href="http://blogs.msdn.com/powershell/archive/2008/12/23/advanced-functions-and-test-leapyear-ps1.aspx">great article on using the&#160; capabilities of Advanced Functions</a>. They have changed the name from Script Cmdlets to Advanced Functions and completely gotten rid of the Cmdlet keyword. </p>
<p>This actually makes a lot of sense IMHO. One of the beauties of this is that there is a smooth path from a basic function to an advanced function</p>
<div>
<div style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px">
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   1:</span> PS C:\&gt; <span style="color: #0000ff">function</span> foo {<span style="color: #006080">&quot;foo $args&quot;</span>}</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   2:</span> PS C:\&gt; foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   3:</span> foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   4:</span> PS C:\&gt; <span style="color: #0000ff">function</span> foo ($a) {<span style="color: #006080">&quot;foo $a&quot;</span>}</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   5:</span> PS C:\&gt; foo -a bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   6:</span> foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   7:</span> PS C:\&gt; <span style="color: #0000ff">function</span> foo {<span style="color: #0000ff">param</span>($a) <span style="color: #006080">&quot;foo $a&quot;</span>}</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   8:</span> PS C:\&gt; foo -a bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">   9:</span> foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  10:</span> PS C:\&gt; <span style="color: #0000ff">function</span> foo {<span style="color: #0000ff">param</span>([Parameter(ValueFromPipeline=$true)]$a) <span style="color: #006080">&quot;foo $a&quot;</span>}</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  11:</span> PS C:\&gt; <span style="color: #006080">&quot;bar&quot;</span> | foo</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  12:</span> foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  13:</span> PS C:\&gt; foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  14:</span> foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  15:</span> PS C:\&gt; foo -a bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: #f4f4f4; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  16:</span> foo bar</pre>
<pre style="border-bottom-style: none; padding-bottom: 0px; line-height: 12pt; border-right-style: none; background-color: white; margin: 0em; padding-left: 0px; width: 100%; padding-right: 0px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; border-top-style: none; color: black; font-size: 8pt; border-left-style: none; overflow: visible; padding-top: 0px"><span style="color: #606060">  17:</span> PS C:\&gt;</pre>
</p></div>
</div>
<p>Just by setting some attributes on a parameter, you can get all kinds of great functionality for free.</p>
<p>Jeffrey’s function “Test-LeapYear” is a great example or template to start with. I really like how he used multi-line comments for all the Help documentation. Very slick.</p>
]]></content:encoded>
			<wfw:commentRss>http://get-powershell.com/2008/12/23/industrial-strength-functions-in-v2-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
