<?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; Add-Type</title>
	<atom:link href="http://huddledmasses.org/tag/add-type/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>Using alternate credentials with the FileSystem in PowerShell</title>
		<link>http://huddledmasses.org/using-alternate-credentials-with-the-filesystem-in-powershell/</link>
		<comments>http://huddledmasses.org/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://huddledmasses.org/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://huddledmasses.org/using-alternate-credentials-with-the-filesystem-in-powershell/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>PowerShell needs Shift operators &#8230;</title>
		<link>http://huddledmasses.org/powershell-needs-shift-operators/</link>
		<comments>http://huddledmasses.org/powershell-needs-shift-operators/#comments</comments>
		<pubDate>Sun, 22 Feb 2009 22:18:01 +0000</pubDate>
		<dc:creator>Joel 'Jaykul' Bennett</dc:creator>
				<category><![CDATA[Huddled]]></category>
		<category><![CDATA[Add-Type]]></category>
		<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Shift Operator]]></category>

		<guid isPermaLink="false">http://huddledmasses.org/?p=1094</guid>
		<description><![CDATA[So earlier today someone asked how they could tell if PowerBoots graphics would be hardware accelerated on their system &#8230; and I found the question painful to answer because the answer is that you take the high-order word of the RenderCapability.Tier property, and that indicates 0, 1, or 2 &#8230; where a higher number indicates [...]]]></description>
			<content:encoded><![CDATA[	<p>So earlier today someone asked how they could tell if <a href="http://HuddledMasses.org/PowerBoots">PowerBoots</a> graphics would be hardware accelerated on their system &#8230; and I found the question painful to answer because the answer is that you take the high-order word of the <a href="http://msdn.microsoft.com/en-us/library/system.windows.media.rendercapability.tier.aspx">RenderCapability.Tier</a> property, and that indicates 0, 1, or 2 &#8230; where a higher number indicates a higher level of hardware acceleration:</p>

	<ul>
		<li><strong>Rendering Tier 0</strong> No graphics hardware acceleration. The DirectX version level is less than version 7.0.</li>
		<li><strong>Rendering Tier 1</strong> Partial graphics hardware acceleration. The DirectX version level is greater than or equal to version 7.0, and lesser than version 9.0.</li>
	</ul>
	<ul>
		<li><strong>Rendering Tier 2</strong> Most graphics features use graphics hardware acceleration. The DirectX version level is greater than or equal to version 9.0. </li>
	</ul>

<div class="zemanta-img floatright" style="border: 2px solid rgb(51, 102, 153); margin: 2px; padding: 2px;"><div><a href="http://commons.wikipedia.org/wiki/Image:Rotate_left_logically.svg"><img src="http://upload.wikimedia.org/wikipedia/commons/thumb/5/5c/Rotate_left_logically.svg/202px-Rotate_left_logically.svg.png" alt="Logical and arithmetic rotate one bit left" title="Logical and arithmetic rotate one bit left" /></a><br />
<span style="font-size: 0.9em; font-weight: bold;">Shift-Left 1, via <a href="http://commons.wikipedia.org/wiki/Image:Rotate_left_logically.svg">Wikipedia</a></span></div></div>

	<p>The problem is that in PowerShell, getting the &#8220;high-order word&#8221; of an integer is a little annoying, because the normal way to do that is to right-shift the integer to throw away the low-order word &#8230; and PowerShell is missing the shift operators. Why? I don&#8217;t know. In any case, I figured, well, I&#8217;ll just write it as a function with a call out to C# to make my life simpler.  The one catch is that the Add-Type cmdlet that lets you inject C# classes is new in PowerShell 2.0, so if you want to use this script in PowerShell 1.0 you need to get the <a href="http://poshcode.org/720">New-Type</a> function from PoshCode and replace Add-Type with New-Type in the script.</p>

<span id="more-1094"></span>

	<p>I wrote a simple little static C# class to actually do the shifting, and then a pair of functions: Shift-Left and Shift-Right which can even work in the pipeline. NOTE: it assume the values are passed in by index, so when you&#8217;re in the pipeline it should only have one parameter (<code>$x</code>) which will be the shift count, but when you&#8217;re passing both as parameters to the function, $y is the shift count.</p>

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

<div class="zemanta-pixie"><a class="zemanta-pixie-a" href="http://reblog.zemanta.com/zemified/23e567b3-6ecd-4888-a386-f812a192d2e7/" title="Zemified by Zemanta"><img class="zemanta-pixie-img" src="http://img.zemanta.com/reblog_e.png?x-id=23e567b3-6ecd-4888-a386-f812a192d2e7" alt="Reblog this post [with Zemanta]" /></a></div>]]></content:encoded>
			<wfw:commentRss>http://huddledmasses.org/powershell-needs-shift-operators/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

