<?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; BestPractices</title>
	<atom:link href="http://huddledmasses.org/tag/bestpractices/feed/" rel="self" type="application/rss+xml" />
	<link>http://huddledmasses.org</link>
	<description>You can do more than breathe for free...</description>
	<lastBuildDate>Sat, 28 Jan 2012 21:37:20 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
<cloud domain='huddledmasses.org' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
		<item>
		<title>Getting Started with PowerShell 2 &#8211; Part 3</title>
		<link>http://huddledmasses.org/getting-started-with-powershell-2-part-3/</link>
		<comments>http://huddledmasses.org/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://huddledmasses.org/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://huddledmasses.org/getting-started-with-powershell-2-part-3/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>

