
<?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>Lead, Follow, or Move &#187; Scripting</title>
	<atom:link href="http://www.leadfollowmove.com/archives/tag/scripting/feed" rel="self" type="application/rss+xml" />
	<link>http://www.leadfollowmove.com</link>
	<description>Adam Bell on Deployment, Automation, PowerShell et al</description>
	<lastBuildDate>Thu, 22 Apr 2010 14:34:55 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Error checking in PowerShell</title>
		<link>http://www.leadfollowmove.com/archives/powershell/error-checking-in-powershell</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/error-checking-in-powershell#comments</comments>
		<pubDate>Tue, 02 Oct 2007 22:22:33 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/error-checking-in-powershell</guid>
		<description><![CDATA[I recently thought I ought to lift my scripting game and introduce some error checking into my PowerShell scripts. After a quick google I found this excellent article from the Scripting Guys. In essence, we set: $error.clear() $erroractionpreference = &#34;SilentlyContinue&#34; And then use, the following statement to test whether the last command was successful: if [...]]]></description>
			<content:encoded><![CDATA[<p>I recently thought I ought to lift my scripting game and introduce some error checking into my PowerShell scripts.</p>
<p>After a quick <a href="http://www.google.co.uk/search?hl=en&#038;q=powershell+error+checking&#038;btnG=Search&#038;meta=">google</a> I found <a href="http://www.microsoft.com/technet/scriptcenter/funzone/games/solutions07/bpssol07.mspx">this</a> excellent article from the Scripting Guys.</p>
<p>In essence, we set:</p>
<div class="quickcodenoclick"><code><br />
$error.clear()<br />
$erroractionpreference = &quot;SilentlyContinue&quot;<br />
</code></div>
<p>And then use, the following statement to test whether the last command was successful:</p>
<div class="quickcodenoclick"><code><br />
if (!$?)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&quot;An error has occurred.&quot;<br />
}<br />
</code></div>
<p>If you just want to know whether an error occurred within the script, you can test:</p>
<div class="quickcodenoclick"><code><br />
if ($error[0])<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&quot;An error has occurred&quot;<br />
}<br />
</code></div>
<p>The article is good and well worth a read. Watch this space for some examples shortly &#8230;.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/error-checking-in-powershell/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Windows Script 5.7 Released!</title>
		<link>http://www.leadfollowmove.com/archives/scripting/windows-script-57-released</link>
		<comments>http://www.leadfollowmove.com/archives/scripting/windows-script-57-released#comments</comments>
		<pubDate>Fri, 10 Aug 2007 10:51:38 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[Scripting]]></category>
		<category><![CDATA[Announcements]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/scripting/windows-script-57-released</guid>
		<description><![CDATA[I didn&#8217;t see this one coming. Microsoft have released 5.7 of Windows Script. This provides an update for: Microsoft® Windows® Script containing Visual Basic® Script Edition (VBScript.) Version 5.7, JScript® Version 5.7, Windows Script Components, Windows Script Host 5.7, and Windows Script Runtime Version 5.7. Get your downloads here: Windows 2000 Windows XP Windows Server [...]]]></description>
			<content:encoded><![CDATA[<p>I didn&#8217;t see this one coming. </p>
<p>Microsoft have released 5.7 of Windows Script. This provides an update for:</p>
<blockquote><p>
Microsoft® Windows® Script containing Visual Basic® Script Edition (VBScript.) Version 5.7, JScript® Version 5.7, Windows Script Components, Windows Script Host 5.7, and Windows Script Runtime Version 5.7.
</p></blockquote>
<p>Get your downloads here:<br />
<a title="Microsoft Download: Windows Script 5.7 for Windows 2000" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=c03d3e49-b40e-4ca1-a0c7-cc135ec4d2be&#038;DisplayLang=en">Windows 2000</a><br />
<a title="Microsoft Download: Windows Script 5.7 for Windows XP" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=47809025-d896-482e-a0d6-524e7e844d81&#038;DisplayLang=en">Windows XP</a><br />
<a title="Microsoft Download: Windows Script 5.7 for Windows Server 2003" href="http://www.microsoft.com/downloads/details.aspx?FamilyID=f00cb8c0-32e9-411d-a896-f2cd5ef21eb4&#038;DisplayLang=en">Windows Server 2003</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/scripting/windows-script-57-released/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Utilising CMD behaviour in PowerShell</title>
		<link>http://www.leadfollowmove.com/archives/powershell/utilising-cmd-behaviour-in-powershell</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/utilising-cmd-behaviour-in-powershell#comments</comments>
		<pubDate>Thu, 24 May 2007 22:36:51 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/utilising-cmd-behaviour-in-powershell</guid>
		<description><![CDATA[A couple of days ago Jeffrey Snover posted this article on the Windows PowerShell Team blog. I had noted this behaviour previously and just put it down to a quirk of PowerShell. So I&#8217;ve been musing over what I miss from the CMD that I&#8217;d like available in PoSh. To help jog my memory I [...]]]></description>
			<content:encoded><![CDATA[<p>A couple of days ago Jeffrey Snover posted <a href="http://blogs.msdn.com/powershell/archive/2007/05/22/cmd-exe-compatibility.aspx">this</a> article on the Windows PowerShell Team blog. I had noted this behaviour previously and just put it down to a quirk of PowerShell.</p>
<p>So I&#8217;ve been musing over what I miss from the CMD that I&#8217;d like available in PoSh. To help jog my memory I fired up a CMD session and typed</p>
<div class="quickcodenoclick"><code><br />
help &gt; help.txt<br />
</code></div>
<p>That&#8217;s quite a list!<br />
<a href='http://www.leadfollowmove.com/?attachment_id=135' rel='attachment wp-att-135' title='CMD Help output in notepad'><img src='http://www.leadfollowmove.com/wp-content/uploads/cmd-help.thumbnail.png' alt='CMD Help output in notepad' /></a><br />
I started to take a look at what command I might be interested in outside of the few Jeffrey highlighted. At first glance I just though about writing a loop to check if an alias already existed, and then create a function for them all. Looking at the list though and some of these are not suitable for PoSh anymore.</p>
<p>So other than <em>dir</em>, <em>assoc</em>, and <em>vol</em> is there anything to note? Well I did find that a few of the commands appear to be supported natively.<br />
<a href='http://www.leadfollowmove.com/archives/powershell/utilising-cmd-behaviour-in-powershell/attachment/powershell-cmds/' rel='attachment wp-att-133' title='PowerShell CMD’s'><img src='http://www.leadfollowmove.com/wp-content/uploads/powershell-cmds.thumbnail.png' alt='PowerShell CMD’s' /></a><br />
Well I agree with Mark Russinovich. I like to be able to call the <em>dir</em> command with switches sometimes, but admittedly I&#8217;ve been weaned off its use since using PoSH full time.</p>
<p>I think the only other command I would be tempted to map over would be <em>ftype</em>. It&#8217;s a compliment to <em>assoc</em>, and could have an occasional use.</p>
<p><a href='http://www.leadfollowmove.com/archives/powershell/utilising-cmd-behaviour-in-powershell/attachment/ftype-command-in-powershell/' rel='attachment wp-att-134' title='Ftype command in PowerShell'><img src='http://www.leadfollowmove.com/wp-content/uploads/powershell-ftype.thumbnail.png' alt='Ftype command in PowerShell' /></a><br />
Notice that there deliberately appears to be no open action associated with the <em>Microsoft.PowerShellScript.1</em> ProgId&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/utilising-cmd-behaviour-in-powershell/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Converting a GUID string to octet string</title>
		<link>http://www.leadfollowmove.com/archives/powershell/converting-a-guid-string-to-octet-string</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/converting-a-guid-string-to-octet-string#comments</comments>
		<pubDate>Mon, 09 Apr 2007 11:50:35 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/converting-a-guid-string-to-octet-string</guid>
		<description><![CDATA[GUID&#8217;s seem to pop up everywhere these days. Where ever there&#8217;s a need to uniquely identify an object there&#8217;s a good chance that the GUID fits the bill. The two main formats that I&#8217;ve encountered them in in Active Directory and Windows Installer has been string, or binary octet string format. Now despite the fact [...]]]></description>
			<content:encoded><![CDATA[<p>GUID&#8217;s seem to pop up everywhere these days. Where ever there&#8217;s a need to uniquely identify an object there&#8217;s a good chance that the GUID fits the bill.</p>
<p>The two main formats that I&#8217;ve encountered them in in Active Directory and Windows Installer has been <em>string</em>, or <em>binary octet string</em> format. Now despite the fact they look quite different, they are in fact the same.</p>
<p>Here&#8217;s the process:<br />
1) Strip out the hyphens</p>
<p>Looking at the remaining string in bytes (groupings of pairs) then<br />
2) Reverse the order in the first 3 bytes<br />
3) concatenate the remaining bytes with the reversed bytes.</p>
<p>for example:<br />
    7147a8de-129a-4edd-9533-83982050211f<br />
becomes:<br />
    dea847719a12dd4e953383982050211f</p>
<p>And our sample code:<br />
<a class="quickcode" title="Code" href="javascript:toggleLayer('quickcode721');">:convert.ps1</a></p>
<div id="quickcode721" class="quickcode"><code><br />
# Convert GUID to Octet String<br />
# Each pair needs to be written in Hex in the format: 4 bytes-2 bytes-2 bytes-2 bytes-6 bytes<br />
# The first 3 byte sequences are written in reverse.<br />
# &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-<br />
function ReverseBytes<br />
# &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-<br />
{<br />
Param (<br />
&nbsp;&nbsp;$StringOfBytes<br />
&nbsp;&nbsp;)<br />
&nbsp;&nbsp;for ($i=0; $i -lt $StringOfBytes.length; $i+=2)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;$NuString= $StringOfBytes.substring($i,2)+$NuString <br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;return $NuString<br />
}<br />
# &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-<br />
function convertguid<br />
# &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-<br />
{<br />
Param (<br />
&nbsp;&nbsp;$guid<br />
&nbsp;&nbsp;)<br />
&nbsp;&nbsp;$partA, $PartB, $PartC, $TheRest = $guid.split(&quot;-&quot;)<br />
&nbsp;&nbsp;return ( ReverseBytes $PartA ) + ( ReverseBytes $PartB ) `<br />
&nbsp;&nbsp;&nbsp;&nbsp;+ ( ReverseBytes $PartC ) + $TheRest<br />
}<br />
# &#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-&#45;&#45;-<br />
$a = [system.guid]::NewGuid().ToString()<br />
write-host $a<br />
convertguid ( $a )<br />
</code></div>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/converting-a-guid-string-to-octet-string/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Power Lines</title>
		<link>http://www.leadfollowmove.com/archives/powershell/power-lines</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/power-lines#comments</comments>
		<pubDate>Wed, 04 Apr 2007 10:01:03 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Power Lines]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/power-lines</guid>
		<description><![CDATA[Once you&#8217;ve been using PowerShell for a while you start to notice that you can often get the job done using just one line of code. These &#8220;one liners&#8221; can sometimes look pretty impressive, but they are also get pretty cryptic! Its a good sales pitch for PowerShell: &#8220;yeah, I can do [insert amazing feat [...]]]></description>
			<content:encoded><![CDATA[<p>Once you&#8217;ve been using PowerShell for a while you start to notice that you can often get the job done using just one line of code. These &#8220;one liners&#8221; can sometimes look pretty impressive, but they are also get pretty cryptic! </p>
<p>Its a good sales pitch for PowerShell: &#8220;yeah, I can do [insert amazing feat here]. It just takes a line of code in PowerShell!&#8221; ;)</p>
<p>I like to think of these, as small bragging rights for the new language, and I call them <strong>Power Lines</strong>.  As I find interesting Power Lines during my wanderings I will start posting them here.</p>
<p>Of course the most impressive Power Lines I&#8217;ve seen around originate from developers, so I make no promises on the &#8220;amazement&#8221; factor ;)</p>
<p>Starting off small here&#8217;s the first one that I&#8217;ve been using today:</p>
<div class="quickcodenoclick"><code><br />
[system.guid]::NewGuid().ToString()<br />
</code></div>
<p>This simply generates a new GUID in string format.</p>
<p>A couple of other examples I&#8217;ve seen around:<br />
<a title="" href="http://blogs.msdn.com/powershell/search.aspx?q=one+liner&#038;p=1">MS PowerShell One Liners</a><br />
<a title= "/\/\o\/\/ PowerShelled" href="http://search.blogger.com/?as_q=one+liner&#038;ie=UTF-8&#038;ui=blg&#038;bl_url=mow001.blogspot.com&#038;x=0&#038;y=0">MOW&#8217;s old blog</a><br />
<a title="Google: Search on PowerShell One Liner" href="http://www.google.co.uk/search?hl=en&#038;client=firefox-a&#038;channel=s&#038;rls=org.mozilla%3Aen-US%3Aofficial&#038;hs=NLh&#038;q=powershell+one+liner&#038;btnG=Search&#038;meta=">Google</a></p>
<p>What&#8217;s your Power Line?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/power-lines/feed</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Static Members and PowerShell obscurity</title>
		<link>http://www.leadfollowmove.com/archives/powershell/static-members-and-powershell-obscurity</link>
		<comments>http://www.leadfollowmove.com/archives/powershell/static-members-and-powershell-obscurity#comments</comments>
		<pubDate>Thu, 29 Mar 2007 20:13:57 +0000</pubDate>
		<dc:creator>Adam Bell</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Scripting]]></category>

		<guid isPermaLink="false">http://www.leadfollowmove.com/archives/powershell/static-members-and-powershell-obscurity</guid>
		<description><![CDATA[I recently posted a question on the Microsoft PowerShell NG on how to use a .Net function in PowerShell. It might be easier if I put this in context. I had a requirement to take a string containing a mixture of upper and lowercase letters, and rewrite it with a hyphen preceding the uppercase letters. [...]]]></description>
			<content:encoded><![CDATA[<p>I recently posted a question on the <a title="Google: MS PS NG" href="http://groups.google.co.uk/group/microsoft.public.windows.powershell/topics?hl=en">Microsoft PowerShell NG</a> on how to use a .Net function in PowerShell.</p>
<p>It might be easier if I put this in context. I had a requirement to take a string containing a mixture of upper and lowercase letters, and rewrite it with a hyphen preceding the uppercase letters. This didn&#8217;t seem like a particularly daunting task. As MSDN is my new best friend I thought I&#8217;d have a browse and see what functions may be able to help.</p>
<p>I found the <a title="MSDN: Char.IsUpper Method " href="http://msdn2.microsoft.com/en-us/library/system.char.isupper.aspx">IsUpper</a> function and then went about trying to use <em>Get-Member</em> to try and see if I could expose this within PowerShell. No dice.</p>
<p><a title="MS NG: IsUpper method in PowerShell?" href="http://groups.google.co.uk/group/microsoft.public.windows.powershell/browse_thread/thread/454acbab2008baa/6fd83c906a22cdae?lnk=st&#038;q=powershell+static+&#038;rnum=1&#038;hl=en#6fd83c906a22cdae">Duncan Smith</a> was kind enough to provide some light on the subject. </p>
<p>So within PowerShell we can access this as a <em>Static Member</em>. Now I&#8217;ve seen a few static members used in PowerShell scripts so far, but as a non-coder being able to uncover these to access functions and methods within .Net still seems something of a black art to me. I&#8217;m hoping that as time goes by, and my exposure to more and more programming concepts these things will start to become more apparent. I&#8217;ll let you know ;)</p>
<p>And below is my script to give you another example:<br />
<a class="quickcode" title="Code" href="javascript:toggleLayer('quickcode681');">IsUpper.ps1</a></p>
<div id="quickcode681" class="quickcode"><code><br />
$MyString = &quot;ThisIsMyString&quot;<br />
$NuString = &quot;&quot;<br />
&nbsp;<br />
for ($i=0; $i -lt $MyString.length; $i++)<br />
{<br />
&nbsp;&nbsp;If ([char]::IsUpper($MyString.chars($i)))<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;$NuString = $NuString+&quot;-&quot;+$MyString.Chars($i)<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;Else<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;$NuString = $NuString+$MyString.Chars($i)<br />
&nbsp;&nbsp;}<br />
}<br />
# trim the leading &quot;-&quot; if the string starts with a capital.<br />
$NuString = $NuString.substring(1,$NuString.length-1)<br />
&nbsp;<br />
write-host $NuString<br />
</code></div>
]]></content:encoded>
			<wfw:commentRss>http://www.leadfollowmove.com/archives/powershell/static-members-and-powershell-obscurity/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
