<?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; Windows PowerShell</title>
	<atom:link href="http://joelbennett.net/tag/windows-powershell/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>Using alternate credentials with the FileSystem in PowerShell</title>
		<link>http://joelbennett.net/using-alternate-credentials-with-the-filesystem-in-powershell/</link>
		<comments>http://joelbennett.net/using-alternate-credentials-with-the-filesystem-in-powershell/#comments</comments>
		<pubDate>Fri, 21 May 2010 04:53:55 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Add-Type]]></category>
		<category><![CDATA[Credentials]]></category>
		<category><![CDATA[FileShare]]></category>
		<category><![CDATA[PInvoke]]></category>
		<category><![CDATA[Server]]></category>
		<category><![CDATA[UNC]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1478</guid>
		<description><![CDATA[In PowerShell, cmdlets like Get-ChildItem and Get-Content support a -Credential parameter so you can access resources that require you to log in&#8230; the problem is that the built-in FileSystem provider does not. So as an example, if you have a server on a different domain and you want to copy files off of it, you [...]]]></description>
			<content:encoded><![CDATA[	<p>In PowerShell, cmdlets like Get-ChildItem and Get-Content support a -Credential parameter so you can access resources that require you to log in&#8230; the problem is that the built-in FileSystem provider does not. So as an example, if you have a server on a different domain and you want to copy files off of it, you can&#8217;t do this:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #660033; font-weight: bold;">$cred</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Credential</span></span><br />
<span style="color: #0066cc; font-style: italic;">Copy-<span style="font-style: normal;">Item</span></span> \Server\Share\Folder\<span style="color: #66cc66;">*</span>.<span style="color: #003366;">log</span> C:\Logs <span style="color: #000066;">-Credential</span> <span style="color: #660033; font-weight: bold;">$cred</span></div>

	<p>That will throw an error: &#8220;Cannot retrieve the dynamic parameters for the cmdlet. The provider does not support the use of credentials. Perform the operation again without specifying credentials.&#8221;</p>

	<h4>Impersonation</h4>

	<p>To solve this problem at work, I&#8217;ve written an impersonation module. It basically has two methods: Push-ImpersonationContext and Pop-ImpersonationContext. There is one catch: you need to be running in <strong>single-threaded</strong> apartment mode for it to work, because the impersonation only affects the current <a class="zem_slink" href="http://en.wikipedia.org/wiki/Thread_%28computer_science%29" title="Thread (computer science)" rel="wikipedia">thread</a> (if you&#8217;re not running <code>PowerShell.exe -STA</code>, your commands execute on a <a class="zem_slink" href="http://en.wikipedia.org/wiki/Thread_pool_pattern" title="Thread pool pattern" rel="wikipedia">thread pool</a>, so you never know from one to the next what thread you&#8217;ll be on). In any case, you use it like this:</p>

	<div class="posh code posh" style="font-family:monospace;"><span style="color: #660033; font-weight: bold;">$cred</span> <span style="color: #66cc66;">=</span> <span style="color: #0066cc; font-style: italic;">Get-<span style="font-style: normal;">Credential</span></span><br />
<span style="color: #0066cc; font-style: italic;">Push-<span style="font-style: normal;">ImpersonationContext</span></span> <span style="color: #660033; font-weight: bold;">$cred</span><br />
<span style="color: #0066cc; font-style: italic;">Copy-<span style="font-style: normal;">Item</span></span> \Server\Share\Folder\<span style="color: #66cc66;">*</span>.<span style="color: #003366;">log</span> C:\Logs<br />
<span style="color: #0066cc; font-style: italic;">Pop-<span style="font-style: normal;">ImpersonationContext</span></span><br />
&nbsp;</div>

	<p>It&#8217;s really very simple, and works great for when you need to access resources across multiple domains. Particularly files, for which PowerShell doesn&#8217;t support alternate credentials at all.  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':(' class='wp-smiley' />   Anyway the module code is on PoshCode, save it to your Documents\WindowsPowerShell\Modules\Impersonation\Impersonation.psm1 and use <code>Import-Module Impersonation</code> to load it.  Here you go:</p>

	<p><script type="text/javascript" src="http://PoshCode.org/embed/1867"></script></p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/b2807eb4-e4ea-4df2-8125-5b136d68ce3d/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=b2807eb4-e4ea-4df2-8125-5b136d68ce3d" 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/using-alternate-credentials-with-the-filesystem-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>A question about PowerShell Module Manifests</title>
		<link>http://joelbennett.net/a-question-about-powershell-module-manifests/</link>
		<comments>http://joelbennett.net/a-question-about-powershell-module-manifests/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 05:44:23 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[CPAN]]></category>
		<category><![CDATA[Metadata]]></category>
		<category><![CDATA[Module Manifest]]></category>
		<category><![CDATA[Modules]]></category>
		<category><![CDATA[PoshCode]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1382</guid>
		<description><![CDATA[So, I&#8217;m building the next PoshCode around modules, with CPAN as my model &#8230; Scripts are still there, but they&#8217;re still basically done the way they are now: you just upload a single file. Modules, however, will be treated specially. You&#8217;ll have to have an account to upload, but you&#8217;ll be able to just upload [...]]]></description>
			<content:encoded><![CDATA[	<p>So, I&#8217;m building the next PoshCode around modules, with <span class="caps">CPAN</span> as my model &#8230; </p>

	<p>Scripts are still there, but they&#8217;re still basically done the way they are now: you just upload a single file. </p>

	<p>Modules, however, will be treated specially. You&#8217;ll have to have an account to upload, but you&#8217;ll be able to just upload a .zip file of your module folder using your login and not fill in any other forms. Our system will take care of parsing the metadata out of the <a href="http://msdn.microsoft.com/en-us/library/dd878337%28VS.85%29.aspx">manifest</a> in your module folder.</p>

	<p>The problem is that I need a little data that isn&#8217;t a part of the <a href="http://msdn.microsoft.com/en-us/library/dd878337%28VS.85%29.aspx">standard module manifest</a> format&#8230; and I can&#8217;t add it because PowerShell won&#8217;t load a module with extra fields in the manifest metadata hashtable: https://connect.microsoft.com/PowerShell/feedback/ViewFeedback.aspx?FeedbackID=421837 &#8212; My request was closed &#8220;by design&#8221; early in the beta cycle and I wasn&#8217;t able to convince them to rethink that.</p>

	<p>At a minimum, PoshCode <strong>requires</strong> a <span class="caps">LICENSE</span> field, and a <span class="caps">CATEGORY</span> field (think of the categories on <span class="caps">CPAN</span> or TechNet Script Center).</p>

	<p>So I&#8217;m having an informal poll. (you&#8217;ll have to &#8220;vote&#8221; by commenting or tweeting to me, because I want more than just &#8220;I choose A&#8221;).</p>

	<p>Which option do you prefer, or can you think of a better way:</p>

	<h4>Require the License and Category to be part of the <span class="caps">PRIVATEDATA</span> field in the standard manifest</h4>

	<p>This might require authors to rewrite parts of their modules, because we&#8217;d be forcing PrivateData to be a Hashtable, and to contain keys that they don&#8217;t need in the module.</p>

	<p>Some existing modules use an array in PrivateData, or even a simple string, rather than a Hashtable. However, it&#8217;s not a <strong>huge</strong> difference, and might be the cleanest method: it wouldn&#8217;t require you to manage a second file of data, and the additional data will be easily available to users and scripts via the standard Get-Module output.</p>

	<h4>Add a &#8220;doc comment&#8221; system for Module manifest files.</h4>

	<p>The upside of this is that PoshCode wants to create module-level documentation anyway. If we use documentation comments like those used on functions we would be able to just create our own standard for them, and add any extra fields we need. It would be guaranteed not to conflict with anything you&#8217;re already doing, and in addition to missing metadata, you could have some module-level documentation beyond just the Description field of the metadata.  </p>

	<p>The problem with this is that there&#8217;s no built-in way to parse that, and doing so isn&#8217;t trivial, so you would need to just read it on our website, or read the source of the file, or have our PoshCode cmdlets in order to make any sense of it once you had a module on your system. It doesn&#8217;t integrate with PowerShell in any meaningful way.</p>

	<h4>Embed the extra data right in the manifest hashtable, using a special comment to hide it from Get-Module</h4>

	<p><code lang=&#8220;posh&#8221;<br />
@{<br />
author=&#8220;Joel Bennett&#8221;<br />
description=&#8220;My latest crazy module&#8221;<br />
<#!PoshCode<br />
License=&#8220;Ms-PL&#8221;<br />
Category=&#8220;WPF&#8221;,&#8220;GUI&#8221;,&#8220;Toolkit&#8221;
#><br />
CompanyName=&#8220;Huddled Masses&#8221;<br />
...<br />
}<br />
</code></p>

	<p>I like this because it&#8217;s fairly trivial for us to strip out the comment and just turn that into a plain-old <span class="caps">DATA</span> section.  It also lends itself to reminding the PowerShell team that these fields are missing, and maintains the existing simple syntax of the manifest.  </p>

	<p>The problem here is, again, that the data doesn&#8217;t appear using any of the standard PowerShell tools &#8212; but getting it out is significantly easier than getting out document comments&#8230;</p>

	<h4>Require a separate &#8220;ReadMe.psd1&#8221; (or &#8220;PoshCode.pds1&#8221; or &#8220;Metadata.psd1&#8221;) metadata file</h4>

	<p>You could start with a copy of your module manifest, and then add the extra stuff that PoshCode needs. This would be nice because we would be able to add any extra fields we wanted as mandatory members, and we could include the &#8220;documentation&#8221; stuff I mentioned earlier&#8230;</p>

	<p>But the downside is that it would be a third file (second manifest) that authors would have to maintain and keep current.</p>

	<p>Any thoughts? Suggestions? </p>

	<p>I&#8217;ve put some further thoughts <a href="http://wiki.poshcode.org/PoshCode_Project/CPAN_and_PoshCode_vNext">about CPAN</a> and the <a href="http://wiki.poshcode.org/PoshCode_Project/Module_Upload_System">data problem</a> on the wiki.</p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/afd48ed4-ce64-4ce4-a1a3-9d7daffc69ed/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=afd48ed4-ce64-4ce4-a1a3-9d7daffc69ed" 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/a-question-about-powershell-module-manifests/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Announcing PowerShellGroup.org &#8211; A home for PowerShell User Groups</title>
		<link>http://joelbennett.net/announcing-powershellgroup-org-a-home-for-powershell-user-groups/</link>
		<comments>http://joelbennett.net/announcing-powershellgroup-org-a-home-for-powershell-user-groups/#comments</comments>
		<pubDate>Thu, 07 Jan 2010 04:49:20 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Computers and Internet]]></category>
		<category><![CDATA[User Group]]></category>
		<category><![CDATA[WebHosting]]></category>
		<category><![CDATA[Windows PowerShell]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1379</guid>
		<description><![CDATA[I&#8217;ve just created PowerShellGroup.org &#8212; a new site for PowerShell user groups (starting with: Rochester, Syracuse, Atlanta, Ottawa and of course, the Virtual Group). It&#8217;s open to any PowerShell user groups or script clubs. If you&#8217;re running a PowerShell user group and want simple web-hosting with: top-of-the-site billing for your group (with a url like [...]]]></description>
			<content:encoded><![CDATA[	<p>I&#8217;ve just created <a href="http://PowerShellGroup.org">PowerShellGroup.org</a> &#8212; a new site for PowerShell user groups (starting with: <a href="http://PowerShellGroup.org/rochester-ny">Rochester</a>, <a href="http://PowerShellGroup.org/syracuse-ny">Syracuse</a>, <a href="http://PowerShellGroup.org/atlanta-ga">Atlanta</a>, <a href="http://PowerShellGroup.org/ottawa-ca">Ottawa</a> and of course, the <a href="http://powershellgroup.org/virtual">Virtual Group</a>).</p>

	<p>It&#8217;s open to any PowerShell user groups or script clubs. If you&#8217;re running a PowerShell user group and want simple web-hosting with:
	<ul>
		<li>top-of-the-site billing for your group (with a url like http://powershellgroup.org/rochester-ny )</li>
		<li>group signups</li>
		<li>events, calendars and event signups (including sending out <span class="caps">RSVP</span> emails to your group), and email reminders of events </li>
		<li>a semi-private group section for posting notices, wiki pages, etc.</li>
	</ul>
	<ul>
		<li>optional twitter notification for your posts</li>
	</ul><br />
and so on&#8230;</p>

	<p>Just let me know who you are after you sign up on the site, and I can set you up with &#8220;group administrator&#8221; rights.</p>

	<p>Also, if you have your own web hosting for your user group, but would like to be listed on our site, we can handle that too  <img src='http://joelbennett.net/wordpress/wp-includes/' alt=':)' class='wp-smiley' /> </p>

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/bea06667-02a0-465b-92a4-dd09739c4320/" title="Reblog this post [with Zemanta]"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=bea06667-02a0-465b-92a4-dd09739c4320" 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/announcing-powershellgroup-org-a-home-for-powershell-user-groups/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

