<?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>Huddled Masses &#187; GettingStarted</title>
	<atom:link href="http://joelbennett.net/tag/gettingstarted/feed/" rel="self" type="application/rss+xml" />
	<link>http://joelbennett.net</link>
	<description>The internet home of Joel "Jaykul" Bennett...</description>
	<lastBuildDate>Fri, 27 Apr 2012 05:42:40 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
<cloud domain='joelbennett.net' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>UPNYPUG &#8211; Rochester PowerShell UserGroup Meeting Wednesday</title>
		<link>http://joelbennett.net/upnypug-rochester-powershell-usergroup-meeting-wednesday/</link>
		<comments>http://joelbennett.net/upnypug-rochester-powershell-usergroup-meeting-wednesday/#comments</comments>
		<pubDate>Mon, 18 Jan 2010 15:06:53 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[GettingStarted]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[PowerShellGroup]]></category>
		<category><![CDATA[Presentations]]></category>
		<category><![CDATA[Rochester New York]]></category>
		<category><![CDATA[UserGroup]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1397</guid>
		<description><![CDATA[Image via Wikipedia I&#8217;ve written this up on the new website for our Rochester PowerShell group and on the old blog, and on UGSS Facebook and Twitter &#8230; and now that there&#8217;s only two days left, it&#8217;s time to mention it again, on my blog This Wednesday, January 20, 2010 &#8211; 6:00pm It&#8217;s a new [...]]]></description>
			<content:encoded><![CDATA[<div class="zemanta-img"><div><dl class="wp-caption alignright"><dt class="wp-caption-dt"><a href="http://en.wikipedia.org/wiki/Image:Roc_032c.JPG"><img src="http://upload.wikimedia.org/wikipedia/en/thumb/5/55/Roc_032c.JPG/300px-Roc_032c.JPG" alt="A portion of Rochester's skyline, looking nort..." title="A portion of Rochester's skyline, looking nort..." /></a></dt><dd class="wp-caption-dd zemanta-img-attribution">Image via <a href="http://en.wikipedia.org/wiki/Image:Roc_032c.JPG">Wikipedia</a></dd></dl></div></div>

	<p>I&#8217;ve written this up on the new website for our <a href="http://powershellgroup.org/rochester-ny">Rochester PowerShell group</a> and on the <a href="http://upnypug.wordpress.com">old blog</a>, and on <a href="http://www.usergroupsupportservices.com/UserGroupInformation.ugss?ActiveID=5048">UGSS</a> Facebook and Twitter &#8230; and now that there&#8217;s only two days left, it&#8217;s time to mention it again, on my blog  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

	<h3><a href="http://powershellgroup.org/rochester-ny/events/january-20-2010">This Wednesday, January 20, 2010 &#8211; 6:00pm</a></h3>

	<p>It&#8217;s a new year, and a new opportunity to get started with PowerShell. With the new year, we&#8217;re going to put a renewed focus on trying to make our meetings valuable to everyone. With that in mind, the first Rochester meeting of the upstate New York PowerShell users group in 2010 will feature two separate presentations:</p>

	<h5>Getting Started: The PowerShell Pipeline (100 Level)</h5>

	<ul>
		<li>Different types of commands in PowerShell</li>
		<li>Variable assignment and Pipeline arguments</li>
		<li>Understanding the Pipe</li>
		<li>Why PowerShell&#8217;s pipeline is different</li>
	</ul>
	<ul>
		<li>Exploiting pipelines for fun and profit</li>
	</ul>

	<h5>Creating PowerShell script Modules (300 Level)</h5>

	<ul>
		<li>Turning your script or function into a module</li>
		<li>What makes a function an &#8220;advanced function&#8221;</li>
		<li>Providing in-line help for functions</li>
		<li>Controlling what functions and variables your module exports</li>
	</ul>
	<ul>
		<li>Why you should use Module Metadata files</li>
	</ul>

	<p>Everyone is welcome, from beginners to pros! Bring a friend and introduce them to PowerShell. As always, our meeting will be at New Horizons&#8217; in Henrietta, 50 Methodist Hill Drive, Suite 50.</p>

	<p>In order to keep things on time, we&#8217;ll be starting our presentations at 6:30 exactly, after a short pizza, wings, and networking time starting at 6pm. We only ask that if you can come early for the food you <strong>let us know ahead of time</strong> and come ready to pitch in a few dollars to help cover the cost.</p>

	<p>PS: There will be swag. We have several books, an Arc Mouse, and copies of Windows 7 and Office 2007 to give away&#8230;</p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/cf741a5f-0b2b-4dcc-a258-5d0f0738e972/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=cf741a5f-0b2b-4dcc-a258-5d0f0738e972" alt="Reblog this post [with Zemanta]" /></a><span class="zem-script more-related pretty-attribution"><script type="text/javascript" src="http://static.zemanta.com/readside/loader.js" defer="defer"></script></span></div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/upnypug-rochester-powershell-usergroup-meeting-wednesday/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with PowerShell 2 &#8211; Part 3</title>
		<link>http://joelbennett.net/getting-started-with-powershell-2-part-3/</link>
		<comments>http://joelbennett.net/getting-started-with-powershell-2-part-3/#comments</comments>
		<pubDate>Thu, 24 Jul 2008 04:40:38 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[BestPractices]]></category>
		<category><![CDATA[CodeSigning]]></category>
		<category><![CDATA[GettingStarted]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Profile]]></category>
		<category><![CDATA[WalkThrough]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=561</guid>
		<description><![CDATA[My &#8220;getting started&#8221; series ran out of steam a bit partly because I didn&#8217;t get much feedback on them &#8212; maybe you&#8217;re not interested, or maybe it wasn&#8217;t easy enough, or was just too confusing. In any case, I want to put up at least this one last post to suggest that you get the [...]]]></description>
			<content:encoded><![CDATA[	<p>My &#8220;getting started&#8221; series ran out of steam a bit partly because I didn&#8217;t get much feedback on them &#8212; maybe you&#8217;re not interested, or maybe it wasn&#8217;t easy enough, or was just too confusing. In any case,  I want to put up at least this one last post to suggest that you get the <a href="http://PoshCode.org/">PowerShell Code Repository</a> set up, and to show you the final version of my profile script and how it loads the various pieces it needs, and then I&#8217;ll send you on your way. </p>

	<p>Once you&#8217;ve got your PowerShell <a href="/getting-started-with-powershell-2-part-1">all installed</a> and have set up <a href="/getting-started-with-powershell-2-part-2">your first profile</a> to auto-load &#8230; you&#8217;re going to want some scripts (well, maybe you&#8217;ll want to learn more about how to use PowerShell, but go with me on this)! </p>

	<p>One of the best places to look for scripts is the <a href="http://PoshCode.org/">PowerShell Code Repository</a>, and although you can browse and search on the website, you can also do it using the PoshCode <a href="http://PoshCode.org/PoshCode.psm1">module</a> (or the <span class="em2">version 1 compatible</span> <a href="http://PoshCode.org/PoshCode.ps1">script</a>).  These scripts include a <code>Get-PoshCode</code> cmdlet which you can use with search terms to get a list of scripts and cmdlets back, or with numeric IDs to download scripts (you&#8217;ll see what I mean later on, for now, go ahead and grab the appropriate version of that script).</p>

	<p>I&#8217;m going to assume you put it into your AutoModules folder. If you grabbed the module, it should be saved to  WindowsPowerShell\AutoModules\PoshCode\PoshCode.psm1 otherwise, to WindowsPowerShell\AutoModules\PoshCode.ps1 &#8230; but you may have run into a minor problem if you load the .ps1 version <span style="padding-left:1em;padding-right:1em;text-align:left;" class="em2">)</span>. Both the module and the script are signed, but they are signed by <a href="/JoelBennett_Code-Signing.crt">my self-issued code signing certificate</a> which your computer almost certainly doesn&#8217;t trust&#8230;  You can use the signature to verify that the file hasn&#8217;t been modified since I signed it, but that&#8217;s about all (and even that&#8217;s a bit of a trick). To actually use the script (module), you&#8217;ll need to sign the script yourself (see the steps and how to get a certificate <a href="/getting-started-with-powershell-2-part-2">in part 2</a>).</p>

	<p><strong>If you&#8217;re on CTP2</strong>, this would be a good time to get my Authenticode script module to help with signing, and to learn a little about those PoshCode cmdlets &#8230; <span id="more-561"></span></p>

	<h3>Using PoshCode to get a module.</h3>

	<p>Create a folder in your AutoModules folder named &#8220;Authenticode&#8221; ... and then inside it, try running <code>Get-PoshCode Authenticode</code> &#8230; You should get a list of 3 or more versions of my script, entitled &#8220;Get/Set Signature (CTP2)&#8221;.  You want the latest version, so pick the one with the biggest number for the ID, and run <code>Get-PoshCode 464</code>.  That should download it and save it. You&#8217;ll be able to load it using Add-Module (since Add-Module in the current <span class="caps">CTP</span> doesn&#8217;t care about code-signing), but <strong>first</strong> you need to create a settings file (it will tell you how, if you try to load it without setting it).  change the <strong>CertificateThumbprint</strong> that&#8217;s set in the first line of code in that script &#8212; set it to the thumbprint of your personal code-signing cert (which you&#8217;ve hopefully imported into your certificate store).</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;">#requires -version 2.0</span><br />
<span style="color: #660033;">cd</span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span>\AutoModules<br />
<span style="color: #660033;">mkdir</span> Authenticode <span style="color: #66cc66;">|</span> <span style="color: #660033;">cd</span> <span style="color: #666666; font-style: italic;"># Skip this line if you're on v1</span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">PoshCode</span></span> Authenticode <span style="color: #66cc66;">|</span> <span style="color: #660033;">ft</span> Id, Title, Author, Description <span style="color: #000066;">-auto</span><br />
<span style="color: #666666; font-style: italic;"># assuming the first hit is the newest one ... hit the up arrow, and add:</span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">PoshCode</span></span> <span style="color: #009900;">&quot;Authenticode Signature CTP2&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">select</span> <span style="color: #000066;">-first</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">PoshCode</span></span><br />
<br />
<span style="color: #666666; font-style: italic;"># Make a subdirectory for your LANGUAGE</span><br />
<span style="color: #660033;">mkdir</span> en <span style="color: #66cc66;">|</span> <span style="color: #660033;">cd</span> <br />
<span style="color: #666666; font-style: italic;"># And create a PowerShell Data file with my cert path ...</span><br />
<span style="color: #666666; font-style: italic;"># I loaded my certificate into my user store, but you can use a pfx file </span><br />
<span style="color: #0066cc; font-style: italic;">new-<span style="font-style: normal;">item</span></span> Authenticode.<span style="color: #003366;">psd1</span> <span style="color: #000066;">-type</span> file <span style="color: #000066;">-value</span> <span style="color: #009900;">'&quot;Cert:\CurrentUser\My\F05F583BB5EA4C90E3B9BF1BDD0B657701245BD5&quot;'</span><br />
<br />
<span style="color: #666666; font-style: italic;"># Load the module...</span><br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Module</span></span> Authenticode</div>

	<p>Now you&#8217;ll be able to sign without specifying the certificate each time, and you&#8217;ll be able to pipe files in too, so you could, for instance, sign all the script files in a whole folder tree like: </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033;">ls</span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span>\AutoModules\<span style="color: #66cc66;">*</span> <span style="color: #000066;">-recurse</span> <span style="color: #000066;">-include</span> <span style="color: #66cc66;">*</span>.<span style="color: #003366;">ps1</span>,<span style="color: #66cc66;">*</span>.<span style="color: #003366;">ps1xml</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">AuthenticodeSignature</span></span></div>

	<h3>So, here&#8217;s what I do.</h3>

	<p>First of all, I don&#8217;t <em>actually</em> put .ps1 scripts into the AutoModules folder, I have a separate AutoScripts folder, and I dot-source scripts from there, as well as loading ps1xml format files from it.  I also specifically use a series of scripts there: Aliases.ps1, Variables.ps1, and EyeCandy.ps1.  I assume that the functions of the first two are obvious, the last one is a modified version of the <span class="caps">PSCX</span> prompt and <acronym title="Message of the Day">MOTD</acronym> script to modify my prompt and startup message.</p>

	<p>On top of the PoshCode script module and the Authenticode script module I mentioned earlier, which I use for signing and resigning, and the new CTP2 version of the <a href="http://thepowershellguy.com/blogs/posh/pages/powertab-v2-alpha-1.aspx">PowerTab script module</a>, I also use a source build of the upcoming <span class="caps">PSCX</span> 1.2 release (which needs a bunch of scripts to be useful, so I just renamed their 3-line profile.ps1 to <span class="caps">PSCX</span>.psm1 and stuffed the whole build with all it&#8217;s sub-folders into my WindowsPowerShell\AutoModules\<span class="caps">PSCX</span>).  I also preload my PoshHttp module for downloading files from the web, and I a couple of functions (<a href="http://poshcode.org/477">ellipsis</a> and <a href="http://poshcode.org/424">Get-PerformanceHistory</a>).</p>

	<p>Almost everything else I use I write into scripts (I even use the in-line cmdlet syntax to get full-power parameter parsing in a script file) which I put in directories by category inside my main WindowsPowerShell\Scripts directory (in my profile directory, and add to my path so that I can just run a script named &#8220;Get-<span class="caps">GUID</span>.ps1&#8221; by typing <code>Get-GUID</code> on the command-line.</p>

	<p>Here&#8217;s the profile script off my laptop as an example &#8212; I basically use the same profile on all my PCs, and make changes to the &#8220;Variables&#8221; scripts on each PC to differentiate them.  In fact, I have a sub-directory of my &#8220;WindowsPowerShell\Scripts&#8221; called &#8220;Work&#8221; which I even keep around at home (although I practically never use those scripts at home &#8212; they&#8217;re mostly for resetting servers and doing db queries, and only work from home when my <span class="caps">VPN</span> connection is up).  Let me know if you have any questions.  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=';)' class='wp-smiley' /> </p>

	<p>Incidentally, I use &#8220;RemoteSigned for my Execution Policy &#8212; <span class="em1b">I wish there were a way to <strong>require</strong> signing for just my profile</span>, because then this system would basically protect me from tampering with my auto-run scripts.  However, I&#8217;m actually comfortable not worrying about it any more than I worry about viruses replacing the executable for Notepad++ on my thumbdrive or something &#8212; I <strong>do</strong> realize that this profile script could be simplified a lot if I replaced the signature checking with just using the &#8220;AllSigned&#8221; policy &#8230; but there&#8217;s two <strong>major</strong> problems with that:</p>

	<ol>
		<li>I&#8217;m a PowerShell-ed developer &#8212; I spend a lot of time editing scripts and running them, and re-signing scripts that I&#8217;m working on (even though it&#8217;s just a matter of typing &#8220;sign&#8221; before I run a script) becomes an annoyance, such that if I were working in that environment, I&#8217;d inevitably have a &#8220;Sign-and-Run&#8221; script, which would really make me less secure, rather than more &#8212; for the average <em>user</em>, I <strong>do</strong> think that if you&#8217;re not writing scripts yourself on a daily basis, you should consider using <strong>AllSigned</strong>.</li>
	</ol>
	<ol>
		<li><span class="em2b">PowerShell 2 CTP2 doesn&#8217;t check signatures on modules</span>, so even if I have it set to all-signed, it will load script modules and will <span class="em2">let you dot-source <strong>any</strong> script</span> using the add-module command, so I&#8217;d have to avoid modules altogether to really be 100% secure.</li>
	</ol>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #666666; font-style: italic;"># Set the profile directory first, so we can refer to it for the rest of the script...</span><br />
<span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">Variable</span></span> ProfileDir &nbsp;<span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Split-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$MyInvocation</span>.<span style="color: #003366;">MyCommand</span>.<span style="color: #003366;">Path</span> <span style="color: #000066;">-Parent</span><span style="color: #333;">&#41;</span> <span style="color: #000066;">-Scope</span> Global <span style="color: #000066;">-Option</span> AllScope<br />
<br />
<span style="color: #660033;">cd</span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span><br />
<span style="color: #666666; font-style: italic;"># I have a JOIN function I need for massaging path variables ...</span><br />
<span style="color: #666699; font-weight: bold;">function</span> <span style="color: #333399; font-weight: bold; font-style: italic;">join</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">param</span> &nbsp; &nbsp;<span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$sep</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$append</span>, <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$prepend</span> <span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">begin</span> &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$ofs</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$sep</span>; <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span><span style="color: #003366; font-weight: bold;">string</span><span style="color: #333;">&#91;</span><span style="color: #333;">&#93;</span><span style="color: #333;">&#93;</span></span><span style="color: #660033; font-weight: bold;">$items</span> <span style="color: #66cc66;">=</span> &nbsp;@<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$prepend</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">split</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$sep</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">process</span> &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$items</span> <span style="color: #66cc66;">+=</span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">end</span> &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$items</span> <span style="color: #66cc66;">+=</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$append</span>.<span style="color: #333399; font-weight: bold; font-style: italic;">split</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$sep</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span>; <span style="color: #666699; font-weight: bold;">return</span> <span style="color: #009900;">&quot;$($items -ne '')&quot;</span> <span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## If we're on version two, we HAVE to set the PsPackagePath (it doesn't matter on v1)</span><br />
<span style="color: #660033; font-weight: bold;">$ENV</span>:PSPACKAGEPATH <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;$ProfileDir\AutoModules;$ProfileDir\Modules&quot;</span> <span style="color: #666666; font-style: italic;">#| join &quot;;&quot; -append $ENV:PSPACKAGEPATH</span><br />
<span style="color: #666666; font-style: italic;">## We also want to add our scripts directory to the path</span><br />
<span style="color: #660033; font-weight: bold;">$ENV</span>:PATH <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span>\Script<span style="color: #333;">&#91;</span>s<span style="color: #333;">&#93;</span>,<span style="color: #660033; font-weight: bold;">$ProfileDir</span>\Scripts\<span style="color: #66cc66;">*</span> &nbsp;<span style="color: #66cc66;">|</span> ? <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">PsIsContainer</span> <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">%</span> <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">FullName</span> <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <span style="color: #333399; font-weight: bold; font-style: italic;">Join</span> <span style="color: #009900;">&quot;;&quot;</span> <span style="color: #000066;">-append</span> <span style="color: #660033; font-weight: bold;">$ENV</span>:PATH<br />
<br />
<span style="color: #666666; font-style: italic;">## Now, preload any module in AutoModules that is signed ...</span><br />
<span style="color: #666666; font-style: italic;">###################################################################################################</span><br />
<span style="color: #666666; font-style: italic;">##### &nbsp;NOTE: &nbsp; There's a bug which prevents signing or checking psm1 files</span><br />
<span style="color: #666666; font-style: italic;">##### &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;We work around that bug by using this module called &quot;Authenticode&quot; which </span><br />
<span style="color: #666666; font-style: italic;">##### &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Wraps the Get/Set cmdlets in scripts that check psm1 by renaming them to ps1</span><br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Module</span></span> Authenticode<br />
<span style="color: #666666; font-style: italic;">##### &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Now we can check signatures on .psm1 files ...</span><br />
<span style="color: #666666; font-style: italic;">##### &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;As long as they're in locations where we can rename them without problems</span><br />
<span style="color: #666666; font-style: italic;">## One last exception case:</span><br />
<span style="color: #666666; font-style: italic;">## If PSCX is available, load that FIRST, because others may depend on it.</span><br />
<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Module</span></span> PSCX <span style="color: #000066;">-EA</span> <span style="color: #009900;">&quot;SilentlyContinue&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Now automatically Add-Module the module subfolders ....</span><br />
<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;AutoLoad Modules: &quot;</span> <span style="color: #000066;">-Fore</span> Cyan <span style="color: #000066;">-NoNewLine</span><br />
<span style="color: #660033; font-weight: bold;">$AutoModuleErrors</span> <span style="color: #66cc66;">=</span> @<span style="color: #333;">&#40;</span><span style="color: #333;">&#41;</span><br />
<span style="color: #666699; font-weight: bold;">ForEach</span><span style="color: #333;">&#40;</span> <span style="color: #660033; font-weight: bold;">$module</span> <span style="color: #666699; font-weight: bold;">in</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span>\AutoModules <span style="color: #66cc66;">|</span> ? <span style="color: #333;">&#123;</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">PsIsContainer</span> <span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;"># Write-Host &quot;Test-Module $($module.Name) &quot; -fore Yellow</span><br />
&nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">switch</span> <span style="color: #333;">&#40;</span><span style="color: #660033;">ls</span> <span style="color: #009900;">&quot;$($module.FullName)\*&quot;</span> <span style="color: #000066;">-include</span> <span style="color: #009900;">&quot;$($module.Name).psd1&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;$($module.Name).ps1&quot;</span>, <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;$($module.Name).psm1&quot;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;$($module.Name).dll&quot;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #660033;">sort</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">switch</span><span style="color: #333;">&#40;</span> <span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">Path</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">GetExtension</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Name</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.psd1&quot;</span> <span style="color: #333;">&#123;</span> <span style="color: #cc66cc;">0</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.ps1&quot;</span> &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #cc66cc;">1</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.psm1&quot;</span> <span style="color: #333;">&#123;</span> <span style="color: #cc66cc;">2</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.dll&quot;</span> &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #cc66cc;">3</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> <span style="color: #000066;">-First</span> <span style="color: #cc66cc;">1</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">AuthenticodeSignature</span></span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## If they're signed and valid, Add-Module</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#123;</span> &nbsp;<span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">Signature</span></span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#125;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Module</span></span> <span style="color: #660033; font-weight: bold;">$module</span>.<span style="color: #003366;">Name</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$($module.Name) &quot;</span> <span style="color: #000066;">-fore</span> Cyan <span style="color: #000066;">-NoNewLine</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #666699; font-weight: bold;">continue</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666666; font-style: italic;">## Otherwise, write an error, we don't want this to fail silently</span><br />
&nbsp; &nbsp; &nbsp; default <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$Global</span>:AutoModuleErrors <span style="color: #66cc66;">+=</span> @<span style="color: #333;">&#40;</span><span style="color: #009900;">&quot;&quot;</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> @<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Name&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$module</span>.<span style="color: #003366;">Name</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Path&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Path</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Error&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Status</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;@<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;StatusMessage&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">StatusMessage</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$($module.Name) &quot;</span> <span style="color: #000066;">-fore</span> Red <span style="color: #000066;">-NoNewLine</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span><br />
<br />
<span style="color: #666666; font-style: italic;">## And then, preload any script in AutoScripts that is signed ...</span><br />
<span style="color: #666666; font-style: italic;">###################################################################################################</span><br />
<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;AutoLoad Scripts: &quot;</span> <span style="color: #000066;">-Fore</span> Green <span style="color: #000066;">-NoNewLine</span><br />
<span style="color: #666699; font-weight: bold;">switch</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span>\AutoScripts\<span style="color: #66cc66;">*</span>.<span style="color: #660033;">ps</span><span style="color: #66cc66;">*</span> <span style="color: #000066;">-include</span> <span style="color: #66cc66;">*</span>.<span style="color: #003366;">ps1</span>,<span style="color: #66cc66;">*</span>.<span style="color: #003366;">ps1xml</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">AuthenticodeSignature</span></span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## If they're signed and valid, load them based on type</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Test-<span style="font-style: normal;">Signature</span></span> <span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #333;">&#125;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Path</span> <span style="color: #66cc66;">=</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Path</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">switch</span> <span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">Path</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">GetExtension</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$Path</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.ps1&quot;</span> &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Add-<span style="font-style: normal;">Module</span></span> <span style="color: #660033; font-weight: bold;">$Path</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$([IO.Path]::GetFileNameWithoutExtension($Path)) &quot;</span> <span style="color: #000066;">-Fore</span> Green <span style="color: #000066;">-NoNewLine</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.ps1xml&quot;</span> <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Update-<span style="font-style: normal;">TypeData</span></span> <span style="color: #000066;">-PrependPath</span> <span style="color: #660033; font-weight: bold;">$Path</span> <span style="color: #333;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">continue</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #666666; font-style: italic;">## Otherwise, write an error, we don't want this to fail silently</span><br />
&nbsp; &nbsp;default <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Name</span> <span style="color: #66cc66;">=</span> $<span style="color: #333;">&#40;</span><span style="color: #003366; font-weight: bold;"><span style="color: #333;">&#91;</span>IO.<span style="color: #003366;">Path</span><span style="color: #333;">&#93;</span></span>::<span style="color: #003366;">GetFileNameWithoutExtension</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Path</span><span style="color: #333;">&#41;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #660033; font-weight: bold;">$Global</span>:AutoModuleErrors <span style="color: #66cc66;">+=</span> @<span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span> <span style="color: #66cc66;">|</span> <span style="color: #660033;">Select</span> @<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Name&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$Name</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Error&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Status</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;StatusMessage&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">StatusMessage</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span>,<br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; @<span style="color: #333;">&#123;</span>n<span style="color: #66cc66;">=</span><span style="color: #009900;">&quot;Path&quot;</span>;e<span style="color: #66cc66;">=</span><span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Path</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#125;</span><span style="color: #333;">&#41;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span> <span style="color: #009900;">&quot;$Name &quot;</span> <span style="color: #000066;">-fore</span> Red <span style="color: #000066;">-NoNewLine</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span><br />
<span style="color: #333;">&#125;</span><br />
<span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Host</span></span><br />
<span style="color: #666666; font-style: italic;"># Write out the error messages if we missed loading any modules</span><br />
<span style="color: #666699; font-weight: bold;">if</span><span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$AutoModuleErrors</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp;<span style="color: #660033; font-weight: bold;">$AutoModuleErrors</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Format-<span style="font-style: normal;">Table</span></span> <span style="color: #66cc66;">*</span> <span style="color: #000066;">-auto</span> <span style="color: #66cc66;">|</span> <span style="color: #0066cc; font-style: italic;">Out-<span style="font-style: normal;">Host</span></span><br />
<span style="color: #333;">&#125;</span></div>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/getting-started-with-powershell-2-part-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Getting Started with PowerShell 2 &#8211; Part 2</title>
		<link>http://joelbennett.net/getting-started-with-powershell-2-part-2/</link>
		<comments>http://joelbennett.net/getting-started-with-powershell-2-part-2/#comments</comments>
		<pubDate>Mon, 30 Jun 2008 04:50:05 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[CodeSigning]]></category>
		<category><![CDATA[GettingStarted]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WalkThrough]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/?p=559</guid>
		<description><![CDATA[This continues a short series of posts about getting started with PowerShell &#8230; with a few tips about things you can do to keep your PowerShell profile safe and organized. Your &#8220;profile&#8221; is the script that is automatically loaded when you start up PowerShell. Really, I should say that your profile is the set of [...]]]></description>
			<content:encoded><![CDATA[	<p>This continues a short series of posts about getting started with PowerShell &#8230; with a few tips about things you can do to keep your <a href="http://www.microsoft.com/technet/scriptcenter/topics/winpsh/manual/profile.mspx">PowerShell profile</a> safe and organized.  Your &#8220;profile&#8221; is the script that is automatically loaded when you start up PowerShell.  Really, I <em>should</em> say that your profile is the <em>set</em> of scripts which are loaded <em>by default</em> when you start up PowerShell.  &#8220;By default&#8221; because you can always skip loading them by passing the -NoProfile switch to PowerShell.exe, and a set because PowerShell does, in fact, attempt to load <em>at least</em> four scripts when you run it:</p>

	<p>PowerShell loads &#8220;machine&#8221; profile scripts (which are located in the PowerShell folder) and &#8220;user&#8221; profile scripts (located in your Documents\WindowsPowerShell folder). But there&#8217;s a little more to it than that: PowerShell is a scripting engine which can be hosted inside any app, PowerShell.exe is a DOS-style console which is the default host.  There are several third-party hosts available such as <a href="http://PowerShell.com/">PowerShell Plus</a> and <a href="http://PowerGUI.org/">PowerGUI</a> and several open source hosts such as <a href="http://CodePlex.com/BgShell/">BgShell</a> and <a href="http://CodePlex.com/PoshConsole/">PoshConsole</a> &#8230; in order to support this ecosystem of hosts, the default PowerShell behavior is to load a host-specific profile script (for both the machine settings and the local-user settings).  Not all hosts will do that, but anyway &#8230; the default host loads <code>Microsoft.PowerShell_profile.ps1</code> and <code>Profile.ps1</code> from both the user and machine locations. </p>

	<p>By default, none of those profiles actually exist. Once you&#8217;ve <a href="/getting-started-with-powershell-2-part-1">installed everything as in Part 1</a>, you should have a Profile.ps1 file provided by <acronym title="PowerShell Community Extensions">PSCX</acronym>. This profile defines a whole bunch of values that are used by various <span class="caps">PSCX</span> cmdlets and scripts, so you may want to change some of it, but you should be careful about just deleting things until you&#8217;re well acquainted with the <span class="caps">PSCX</span> cmdlets.  Over time, I&#8217;ve added settings to my profile for other snapins as well, and there gets to be a lot of noise in there that&#8217;s specific to different snapins, so instead of just leaving all of that in my main profile, I rename the Profile.ps1 file provided by <span class="caps">PSCX</span> and then dot-source it from a new blank profile script.</p>

	<p>In fact, and I found that I started collecting a lot of scripts in my WindowsPowerShell folder so I created a sub-folder for them, and I automatically load everything that&#8217;s in that folder, so I don&#8217;t have to manually dot-source things when I add a new snapin profile. </p>

	<h3>Authenticode Signing your auto-load scripts</h3>

	<p>In order to make sure that automatically loading scripts doesn&#8217;t become a way for people to attack my computer, I made a decision awhile ago that I would only auto-load signed scripts. The how and why of this is a bit much to get into, and I wrote about <a href="http://huddledmasses.org/code-signing-with-openssl-and-powershell/">Generating Windows Authenticode Code-Signing Certificates with OpenSSL</a> a while back, so you can read that if you want more details, I want to review the simplest steps.<span id="more-559"></span></p>

	<p> <img src='http://joelbennett.net/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: I should take a moment here to point out, in case you&#8217;re really new to PowerShell, that the first thing you&#8217;ll have to do is fix the error &#8220;File &#8230; cannot be loaded because the execution of scripts is disabled on this system.&#8221;  I originally was just assuming you would have figured that out &#8212; it tells you to read the about_signing help, so you can just execute <code>get-help about_signing</code> and it explains in there what you need to do.  In case you haven&#8217;t gotten that far, before you can execute the New-CodeSigningCert you&#8217;re going to need to run PowerShell as administrator (&#8220;elevated&#8221;) and execute this command: <code>Set-ExecutionPolicy RemoteSigned</code> &#8230; that will let you execute most scripts that you have saved locally without having signed them.  You may want to tighten that up later and set it to &#8220;AllSigned,&#8221; but first you have to be able to sign scripts.</p>

	<h4>Generating a code-signing certificate</h4>

	<p> <img src='http://joelbennett.net/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: I&#8217;ve simplified this a bit, and modified the script to import the certificate to the <em>Current User</em> certificate store if you aren&#8217;t running in an elevated console (in Vista) &#8212; which should work fine if you&#8217;re the only user on your machine that needs to run the scripts &#8212; if you need them in the <em>Local Machine</em> store, you need to be running as administrator.  The script will let you know which it does, so you&#8217;ll know, one way or another.</p>

	<p><strong>Step 1.</strong> Download my <a href="http://huddledmasses.org/?attachment_id=554">PoshCerts package</a> and unpack it in your WindowsPowerShell folder &#8212; lets say in, WindowsPowerShell\PoshCerts\bin.</p>

	<p><strong>Step 2.</strong> Run the New-CodeSigningCert script to generate into the Certs folder. So if you&#8217;re in the WindowsPowerShell directory, you can just run it and you&#8217;ll be prompted for a few pieces of information that the certificates require, plus two passwords &#8212; and all of the keys will be generated into the Certs folder as files, and imported to your local store.  Make sure you make a note of those passwords.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033;">cd</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Split-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$Profile</span><span style="color: #333;">&#41;</span>\PoshCerts\<br />
.\bin\<span style="color: #0066cc; font-style: italic;">New-<span style="font-style: normal;">CodeSigningCert</span></span>.<span style="color: #003366;">ps1</span> <span style="color: #660033; font-weight: bold;">$pwd</span> <span style="color: #009900;">&quot;[Your Name]&quot;</span> <span style="color: #009900;">&quot;[Your Email]&quot;</span> <span style="color: #000066;">-ImportAll</span></div>

	<p> <img src='http://joelbennett.net/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: I came up with a <strong>Step 3.</strong> Under most circumstances (that is, unless you were planning on running a corporate Certificate Authority), you&#8217;ll have no further use for the CA certificate, If you want to make sure that nobody can abuse your root CA &#8230; you can and should just delete the private certificates, like so: <code>Remove-Item *Root-CA.* -exclude *.crt</code></p>

	<h4>Signing Scripts</h4>

	<p>You can now sign scripts at will using the <strong>pfx</strong> file generated in step 2 with the Get-PfxCertificate cmdlet, or the Cert: provider (you have use -ImportAll when you call New-CodeSigningCert, not just -Import &#8212; that causes the import of your code-signing certificate to the &#8220;My&#8221; store &#8230; then you can do <code>Get-ChildItem &#34;Cert:\CurrentUser\My\$thumbprint&#34;</code> where $thumbprint is your certificate&#8217;s thumbprint).  </p>

	<p>Let&#8217;s rename our Profile.ps1 script and then sign it.  We&#8217;ll create create a folder called &#8220;AutoModules&#8221; to stick your <span class="caps">PSCX</span> profile (and any future such scripts) in. If you&#8217;re still on PowerShell 1, you&#8217;ll just put the .ps1 files into that folder, and we&#8217;ll dot-source them. </p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033;">cd</span> <span style="color: #333;">&#40;</span><span style="color: #0066cc; font-style: italic;">Split-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$Profile</span><span style="color: #333;">&#41;</span><br />
<span style="color: #660033;">mkdir</span> AutoModules<br />
<span style="color: #666666; font-style: italic;"># Sign it (you'll reuse this exact code in a moment)</span><br />
<span style="color: #0066cc; font-style: italic;">Set-<span style="font-style: normal;">AuthenticodeSignature</span></span> <span style="color: #000066;">-Cert</span> <span style="color: #333;">&#40;</span><br />
&nbsp; &nbsp; <span style="color: #666666; font-style: italic;"># You'll be prompted for your code-signing cert password here:</span><br />
&nbsp; &nbsp; <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">PfxCertificate</span></span> .\PoshCerts\<span style="color: #66cc66;">*</span>Code<span style="color: #66cc66;">-</span>Signing.<span style="color: #003366;">pfx</span><br />
&nbsp; &nbsp; <span style="color: #333;">&#41;</span> .\Profile.<span style="color: #003366;">ps1</span><br />
<span style="color: #666666; font-style: italic;"># Now move it (the signature doesn't care about the file name).</span><br />
<span style="color: #660033;">mv</span> .\Profile.<span style="color: #003366;">ps1</span> .\AutoModules\PSCX.<span style="color: #003366;">ps1</span><br />
&nbsp;</div>

	<p> <img src='http://joelbennett.net/wordpress/wp-includes/' alt='[new]' class='wp-smiley' />  <strong>Edit</strong>: The simplest</p>

	<h4>Checking for valid signatures</h4>

	<p>Once you&#8217;ve got that set up, we need to create the new profile script and modify it to load not just the <span class="caps">PSCX</span> module, but any other <strong>signed</strong> scripts we put in there.  Paste this into your new Profile.ps1, and don&#8217;t forget to sign it.</p>

	<div class="posh code posh" style="font-family:monospace;"><br />
<span style="color: #660033; font-weight: bold;">$ProfileDir</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Split-<span style="font-style: normal;">Path</span></span> <span style="color: #660033; font-weight: bold;">$MyInvocation</span>.<span style="color: #003366;">MyCommand</span>.<span style="color: #003366;">Path</span><br />
<br />
<span style="color: #666666; font-style: italic;">## If we're on version two, we need to set the PsPackagePath (it doesn't hurt anything anyway)</span><br />
<span style="color: #660033; font-weight: bold;">$ENV</span>:PSPACKAGEPATH <span style="color: #66cc66;">=</span> <span style="color: #009900;">&quot;$ProfileDir\AutoModules&quot;</span><br />
<br />
<span style="color: #666666; font-style: italic;">## Now, preload any script in AutoModules that is signed ...</span><br />
<span style="color: #666666; font-style: italic;">##### Problem 1: &nbsp;There's a bug which prevents signing or checking psm1 files</span><br />
<span style="color: #666666; font-style: italic;">##### I'll show you how to work around that in Part 3</span><br />
<span style="color: #666666; font-style: italic;">##### For now you don't have any, so this is quite simple:</span><br />
<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span> <span style="color: #660033; font-weight: bold;">$ProfileDir</span>\AutoModules\<span style="color: #66cc66;">*</span> <span style="color: #000066;">-include</span> <span style="color: #66cc66;">*</span>.<span style="color: #003366;">ps1</span> <span style="color: #000066;">-recurse</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">AuthenticodeSignature</span></span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;Where<span style="color: #66cc66;">-</span>Object <span style="color: #333;">&#123;</span><span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">Status</span> <span style="color: #000066;">-eq</span> <span style="color: #009900;">&quot;Valid&quot;</span><span style="color: #333;">&#125;</span> <span style="color: #66cc66;">|</span> <br />
&nbsp; &nbsp;<span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">ChildItem</span></span> <span style="color: #66cc66;">|</span> <span style="color: #66cc66;">&amp;</span><span style="color: #333;">&#123;</span> <span style="color: #666699; font-weight: bold;">PROCESS</span> <span style="color: #333;">&#123;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #666699; font-weight: bold;">switch</span> <span style="color: #000066;">-regex</span> <span style="color: #333;">&#40;</span><span style="color: #660033; font-weight: bold;">$_</span><span style="color: #333;">&#41;</span> <span style="color: #333;">&#123;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.*\.ps1$&quot;</span> &nbsp; &nbsp;<span style="color: #333;">&#123;</span> . <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">FullName</span>; <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Verbose</span></span> <span style="color: #009900;">&quot;Loaded $_&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #009900;">&quot;.*\.ps1xml$&quot;</span> <span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Update-<span style="font-style: normal;">TypeData</span></span> <span style="color: #000066;">-PrependPath</span> <span style="color: #660033; font-weight: bold;">$_</span>.<span style="color: #003366;">FullName</span> &nbsp;<span style="color: #333;">&#125;</span> <br />
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp;default &nbsp; &nbsp; &nbsp; &nbsp;<span style="color: #333;">&#123;</span> <span style="color: #0066cc; font-style: italic;">Write-<span style="font-style: normal;">Verbose</span></span> <span style="color: #009900;">&quot;Not sure what to do with: $($_.Name)&quot;</span> <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp; &nbsp; <span style="color: #333;">&#125;</span><br />
&nbsp; &nbsp;<span style="color: #333;">&#125;</span> <span style="color: #333;">&#125;</span></div>

	<p><span class="em2b">If you&#8217;re testing PowerShell 2</span>, you&#8217;ll want to treat these scripts as <a href="/powershell-modules/">Modules</a> &#8230; SnapIns themselves can be loaded as modules in PowerShell 2, but so can any script which needs to be dot-sourced. In this case, the easiest thing is to create a subfolder for each one and then use Add-Module with the folder name. There are some problems with that, which I&#8217;ll go into in <a href="http://huddledmasses.org/getting-started-with-powershell-2-part-3/">Part 3</a>.</p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/getting-started-with-powershell-2-part-2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Getting Started with PowerShell 2 &#8211; Part 1</title>
		<link>http://joelbennett.net/getting-started-with-powershell-2-part-1/</link>
		<comments>http://joelbennett.net/getting-started-with-powershell-2-part-1/#comments</comments>
		<pubDate>Sat, 28 Jun 2008 21:29:56 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[GettingStarted]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[WalkThrough]]></category>

		<guid isPermaLink="false">http://HuddledMasses.org/getting-started-with-powershell-2-part-1/</guid>
		<description><![CDATA[I&#8217;ve decided to spend part of this weekend organizing my sock drawer PowerShell profile, and since there doesn&#8217;t seem to be a lot of best practices or prescriptive advice on setting up your PowerShell profile, I thought I&#8217;d write about how I do it, to help any new users out there get started. If you [...]]]></description>
			<content:encoded><![CDATA[	<p>I&#8217;ve decided to spend part of this weekend organizing my <del>sock drawer</del> <ins>PowerShell profile</ins>, and since there doesn&#8217;t seem to be a lot of best practices or prescriptive advice on setting up your PowerShell profile, I thought I&#8217;d write about how I do it, to help any new users out there get started.  </p>

	<p>If you are a .Net developer or a Computer Science researcher, and haven&#8217;t started using PowerShell, let me just make this argument for learning it:</p>

	<blockquote>
		<p>PowerShell cmdlets are simple to write. The additional code required to make a .Net class into a cmdlet is very minor (at a minimum, a single method with a line of code to <code>Write-Output</code> something). Since cmdlets must derive from either Cmdlet or PSCmdlet you can&#8217;t just write every class as a cmdlet, but even non-cmdlet classes can be instantiated via <code>New-Object</code> and their methods and properties can be exercised. </p>
		<p>After writing portions of a recent research project as PowerShell cmdlets, I would say that the ability to write a simple class and then use/execute from the command line and in scripts &#8212; plus the built in automatic argument parsing (PowerShell assigns pipeline input and command line parameters to object properties for you) makes PowerShell cmdlets quite useful for research and development. Because the overhead is so minimal, it minimizes the distractions of creating a user interface and allows you to focus your actual research goals. Additionally, because the PowerShell-specific code can be restricted to attributes and a method or two, the actual classes are still usable for other purposes.  That is, your class is invokable within PowerShell, but it&#8217;s also reusabe within any .Net application, whether Windows.Forms, <span class="caps">WPF</span>, or even web apps.</p>
	</blockquote>

	<p>Of course, since I&#8217;m primarily using PowerShell for research and development, I&#8217;m using the current <span class="caps">CTP</span> 2 release of PowerShell v2, some of what I&#8217;m doing in my profile won&#8217;t work until PowerShell 2 is released (next year?).  I&#8217;ll try to mark the <span class="em2b">CTP-only</span> features appropriately and offer PowerShell 1-compatible workarounds.</p>

	<p>The first step, of course, is to install the software.  To take full advantage of PowerShell 2, you need to have the <a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=333325FD-AE52-4E35-B531-508D977D32A6">.Net Framework 3.5</a> although you could use the <a href="http://www.microsoft.com/downloads/details.aspx?familyid=79BC3B77-E02C-4AD3-AACF-A7633F706BA5&#38;amp;displaylang=en">.Net Framework 2.0</a> instead if you&#8217;re just using PowerShell 1.0.  PowerShell 1 is only available as a &#8220;patch&#8221; so you have to choose the correct download for your platform through the <a href="http://go.microsoft.com/fwlink/?LinkId=79444">Microsoft Download Center</a>. However, since it&#8217;s still in <span class="caps">CTP</span> release, there is an installer for <a href="http://www.microsoft.com/downloads/details.aspx?familyid=7c8051c2-9bfc-4c81-859d-0864979fa403">PowerShell 2 CTP2</a>.</p>

	<p>I also use the <a href="http://www.codeplex.com/PowerShellCX" title="PSCX">PowerShell Community Extensions</a> and recommend them, although there&#8217;s a lot in there you may not use, there&#8217;s also a lot of extremely useful things &#8212; some of which are practically requirements.  <span class="dem1">This package needs updating to work <em>well</em> with PowerShell 2</span>, because PowerShell 2 has implemented natively some of the most popular features in <span class="caps">PSCX</span>, but it&#8217;s just a few minor changes. If you&#8217;re just getting started (or want to follow along with this series of posts), you should let <span class="caps">PSCX</span> install it&#8217;s profile (if you already have a profile, then in order to follow along with these posts, you should <span class="caps">MOVE</span> your profile out of the way before you install <span class="caps">PSCX</span>, and go ahead and let it create a profile from scratch).  </p>

	<p><a href="/getting-started-with-powershell-2-part-2">Part 2</a></p>]]></content:encoded>
			<wfw:commentRss>http://joelbennett.net/getting-started-with-powershell-2-part-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

