<?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>dBlog &#187; Technology</title>
	<atom:link href="http://ddayinc.com/wordpress2/category/technology/feed/" rel="self" type="application/rss+xml" />
	<link>http://ddayinc.com/wordpress2</link>
	<description>Stymie's [periodically] updated ramblings</description>
	<lastBuildDate>Fri, 15 Aug 2008 20:59:21 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>PowerShell and Named Parameters</title>
		<link>http://ddayinc.com/wordpress2/20080815/powershell-and-named-parameters/</link>
		<comments>http://ddayinc.com/wordpress2/20080815/powershell-and-named-parameters/#comments</comments>
		<pubDate>Fri, 15 Aug 2008 20:59:21 +0000</pubDate>
		<dc:creator>D-Day</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>

		<guid isPermaLink="false">http://ddayinc.com/wordpress2/?p=53</guid>
		<description><![CDATA[PowerShell makes for easy named parameter creation (better than VB stuff, and much more better than DOS stuff).  This was something that I asked in the last PowerShell training class I had, but the instructor didn't quite get what I was asking (above his head, probably -- laughs).
To utilize parameters (and named parameters), you [...]]]></description>
			<content:encoded><![CDATA[<p>PowerShell makes for easy named parameter creation (better than VB stuff, and much more better than DOS stuff).  This was something that I asked in the last PowerShell training class I had, but the instructor didn't quite get what I was asking (above his head, probably -- laughs).</p>
<p>To utilize parameters (and named parameters), you can use "<code>param</code>" in your script.  So, you can declare some parameter in the script such as:</p>
<p><code>param([string]$strClusterName = "MyDefaultClusterName")</code></p>
<p>This does a couple of things.  1) Creates a named parameter "strClusterName" of type "string", and 2) sets a default value for it of "MyDefaultClusterName".  You could exclude the setting of a default, and just have a named parameter.  Then you could test for a value, for null, or whatever you felt like.  With that default value in there, if someone calls that script without passing a parameter, it uses the value you set as default (if that wasn't clear).</p>
<p>So, when calling your script, you could pass a parameter like:</p>
<p><code>PS C:\> myScripts\megaScript.ps1 MyOtherClusterName</code></p>
<p>Or, to be explicit and avoid errors due to mismatched positional parameters, you could pass a named parameter to the script like so:</p>
<p><code>PS C:\> myScripts\megaScript.ps1 –strClusterName MyOtherClusterName</code></p>
<p>Using the explicit parameter name when the script only accepts one parameter might seem a bit unnecessary at first glance, but a few months down the road when you're looking at an example usage of your script and see that parameter name, you know what the hell that parameter is…</p>
<p>So, the name of the variable that you create in the <code>param</code> section of code is the name of the parameter to be used at run time.  This holds true for functions, too.  If you had a function like:</p>
<p><code>function dRdp() {<br />
&nbsp; &nbsp; param([string]$strServerName)<br />
&nbsp; &nbsp; mstsc.exe /v:$strServerName<br />
}</code></p>
<p>then, like in the earlier example you could call it with a named parameter as such:</p>
<p><code>PS C:\> dRdp -strServerName myServer010</code></p>
<p>Here, leaving off the parameter name yields the same results -- the parameter is then considered a "positional" parameter.  But, let's say that you wanted to handle other optional parameters.  Now the function is like:</p>
<p><code>function dRdp_v2() {<br />
&nbsp; &nbsp; param([string]$strServerName)<br />
&nbsp; &nbsp; mstsc.exe /v:$strServerName $args[0] $args[1]<br />
}</code></p>
<p>When calling this function with no named parameters like so:</p>
<p><code>PS C:\> dRdp_v2 myServer010 3389</code></p>
<p>the first parameter passed is used for the explicit param "<code>$strServerName</code>", and the second parameter "<code>3389</code>" is returned by "<code>$args[0]</code>" as such:</p>
<p><strong>$strServerName</strong>:  myServer010<br />
<strong>$args[0]</strong>:  3389</p>
<p>Not necessarily what you'd expect for the <code>$args[]</code> array.  Notice here that the named parameter specified in the function definition gets set to the first positional parameter, and the rest of the positional parameters are placed into the <code>$args[]</code> array, starting at index 0.</p>
<p>Now, if you were to call the function with a named parameter, regardless of the position, the parameter in the function gets set to the passed named value, and the rest of the non-named parameters populate the <code>$args[]</code> array. So, calling the function in the following ways gives consistent results:</p>
<p><code>PS C:\> dRdp_v2 -strServerName myServer010 3389<br />
PS C:\> dRdp_v2 3389 -strServerName myServer010</code></p>
<p>A few other notes:<br />
There is another way to make parameters for a function:  you can also define parameters within the parenthesis in the function definition.  This is a bit more natural for people who are accustomed to programming languages in which this is how parameters are specified.  For example, one can define the parameter in the function "<code>dRdp_v2</code>" as follows:</p>
<p><code>function dRdp_v2([string]$strServerName) {<br />
&nbsp; &nbsp; mstsc.exe /v:$strServerName $args[0] $args[1]<br />
}</code></p>
<p>I am partial to this format, mainly because of past exposure, but also because of the increased typing efficiency/tightness of code.</p>
<p>Along the same lines of efficiency are named parameter abbreviations.   When using named parameters in a function call or in calling a script, you can truncate the parameter name as much as desired, so long as the resultant name is still unique among the possible parameters.  That is to say, the shortest non-ambiguous parameter name works.  So, if you made a function with three parameters, "<code>$serverName_str</code>", "<code>$securePort_int</code>" and "<code>$nonSecurePort_int</code>", you could call the function as follows, and all would work:</p>
<p><code>PS C:\> myFn -serverName_str svr010 -securePort_int 443 -nonSecurePort_int 665<br />
PS C:\> myFn -server svr010 -secure 443 -nonSec 665<br />
PS C:\> myFn -ser svr010 -sec 443 -n 665</code></p>
<p>And, the follow example <strong>does not</strong> work, as the first named parameter used, "<code>-s</code>", is ambiguous:</p>
<p><code>## DOES NOT WORK -- the "-s" is ambiguous<br />
PS C:\> myFn -s svr010 -secure 443 -n 665<br />
## DOES NOT WORK</code></p>
<p>There is at least <em>some</em> help available via PowerShell.  The only place I've seen it, though, is:</p>
<p><code>PS C:\> Get-Help -Full about_function</code></p>
<p>So, now named parameters are going to rule the world.</p>
]]></content:encoded>
			<wfw:commentRss>http://ddayinc.com/wordpress2/20080815/powershell-and-named-parameters/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>VMware VI Toolkit (for Windows) &#8212; new Functions</title>
		<link>http://ddayinc.com/wordpress2/20080804/vmware-vi-toolkit-for-windows-new-functions/</link>
		<comments>http://ddayinc.com/wordpress2/20080804/vmware-vi-toolkit-for-windows-new-functions/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 04:23:50 +0000</pubDate>
		<dc:creator>D-Day</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[vi toolkit]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://ddayinc.com/wordpress2/?p=32</guid>
		<description><![CDATA[What?  Two posts?  Well, as previously mentioned, the final 1.0 version of the VMware VI Toolkit (for Windows) came out 25 Jul 2008.  I was excited to see that it fixed the issue of connecting to VMware Server 2 RC1 (released at the start of July 2008), where "Get-VIServer" commands failed from [...]]]></description>
			<content:encoded><![CDATA[<p>What?  Two posts?  Well, as previously mentioned, the final 1.0 version of the <a href="http://www.vmware.com/support/developer/windowstoolkit/">VMware VI Toolkit (for Windows)</a> came out 25 Jul 2008.  I was excited to see that it fixed the issue of connecting to VMware Server 2 RC1 (released at the start of July 2008), where "<code>Get-VIServer</code>" commands failed from the beta 1.0 Toolkit.</p>
<p>So, in looking around at the new install of the VI Toolkit, I inspected the file that the Toolkit shortcut calls on startup, "<code>Initialize-VIToolkitEnvironment.ps1</code>" (found in \Scripts\).  Huh -- a few new aliases and a couple of new functions. "<code>Get-VIServer</code>", "<code>Get-VC</code>", and "<code>Get-ESX</code>" are all now aliases for the new cmdlet "<code>Connect-VIServer</code>".  The new functions are "<code>New-DatastoreDrive</code>" and "<code>New-VIInventoryDrive</code>".</p>
<p>As described in the VI Toolkit's <a href="http://vmware.com/support/developer/windowstoolkit/wintk10/doc/viwin_admin.pdf">Administrator's Guide</a> (PDF), these new functions seem quite tasty.  For example, to create a new PowerShell PSDrive that corresponds to a given DataStore in your VMware environment, you could issue the commands:</p>
<p><code>Connect-VIServer <em>virtualcenterserver.domain.com</em><br />
New-DatastoreDrive "dsDrive" (Get-Datastore <em>daterstore01</em>)</code></p>
<p>where real names are entered for the VirtualCenter server (or VMware host) and for the Datastore.  Now what?  Well, you can "<code>cd</code>" (alias for "<code>Set-Location</code>") into the newly created DatastoreDrive "dsDrive".  Yeah, that's navigating the Datastore to which you connected -- without need of using the Datastore browser in the VI Client, and without need to SSH to a host.  Sweet.  As the Admin Guide states, "The Datastore Provider (VimDatastore) is designed to provide access to the contents of one or more datastores."</p>
<p>Then there's the Inventory Provider (VimInventory):  "...designed to expose a raw inventory view of the inventory items from a server. It enables interactive navigation and file-style management of the VMware Infrastructure inventory."  And, this can be achieved by doing something like:</p>
<p><code>Connect-VIServer <em>virtualcenterserver.domain.com</em><br />
New-VIInventoryDrive -Name "viInv" -Location (Get-Folder -NoRecursion)</code></p>
<p>You can then act on the inventory objects with the standard cmdlets.  For example:</p>
<p><code>cd viInv:\<em>ha-datacenter\someFolder\vm</em><br />
dir *<em>oldservers01</em>* | Update-Tools</code></p>
<p>Of course, you would want to insert the proper path from your environment in the "<code>cd</code>" statement.  Or, you could just set your location to the root of the PSDrive and explore the path structure using standard "<code>dir</code>" or "<code>Get-ChildItem</code>" commands.  Yet another way to interact with VMware VI items using the VI Toolkit.</p>
<p>(And, in case you forgot, you can always use "<code>Get-PSDrive</code>" to see what PSDrives you currently have.)</p>
]]></content:encoded>
			<wfw:commentRss>http://ddayinc.com/wordpress2/20080804/vmware-vi-toolkit-for-windows-new-functions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>New VMware VI Toolkit 1.0 fixes connectivity to Server 2 RC1</title>
		<link>http://ddayinc.com/wordpress2/20080804/new-vmware-vi-toolkit-10-fixes-connectivity-to-server-2-rc1/</link>
		<comments>http://ddayinc.com/wordpress2/20080804/new-vmware-vi-toolkit-10-fixes-connectivity-to-server-2-rc1/#comments</comments>
		<pubDate>Tue, 05 Aug 2008 03:07:43 +0000</pubDate>
		<dc:creator>D-Day</dc:creator>
				<category><![CDATA[PowerShell]]></category>
		<category><![CDATA[Technology]]></category>
		<category><![CDATA[Virtualization]]></category>
		<category><![CDATA[vi toolkit]]></category>
		<category><![CDATA[vmware]]></category>

		<guid isPermaLink="false">http://ddayinc.com/wordpress2/?p=26</guid>
		<description><![CDATA[Well, the final 1.0 version of the VMware VI Toolkit (for Windows) came out 25 Jul 2008, without much fanfare.  I had been using the 1.0 beta version for a few months, and things seemed good.  I used it against ESX 3.0.1 and VirtualCenter 2.0 at work, and against beta versions of VMware [...]]]></description>
			<content:encoded><![CDATA[<p>Well, the final 1.0 version of the <a href="http://www.vmware.com/support/developer/windowstoolkit/">VMware VI Toolkit (for Windows)</a> came out 25 Jul 2008, without much fanfare.  I had been using the 1.0 beta version for a few months, and things seemed good.  I used it against ESX 3.0.1 and VirtualCenter 2.0 at work, and against beta versions of VMware Server 2.0 at home.</p>
<p>When <a href="http://www.vmware.com/beta/server/">VMware Server 2.0 Release Candidate 1</a> came out, I was quite unhappy that the VI Toolkit seemed to no longer work.  I couldn't even get Get-VIServer to connect to the local web services provided by VMware Server, though it had worked great for the last few months.  Issuing the command:</p>
<p><code>Get-VIServer localhost -Port 8333</code></p>
<p>yielded nothing but an error.  For weeks I tried different steps, from removing the VI Toolkit, to removing the Toolkit and Server, and reinstalling fresh.  No dice.</p>
<p>I had pretty much given up, until I saw that v1.0 final of the Toolkit was available.  After uninstalling the beta version, and installing the new version, jackpot.  The "<code>Get-VIServer</code>" command mentioned above now worked again!  Score.  You might notice that the command is now an Alias for the new cmdlet "<code>Connect-VIServer</code>".  You might not.  There is also a corresponding "<code>Disconnect-VIServer</code>".  Hurray.</p>
<p>Either way, VMware apparently changed something in Server RC1, and the new Toolkit is apparently updated as well to accommodate said change.  I searched the web off and on for a couple of weeks.  Hopefully this post will save someone some trouble.</p>
]]></content:encoded>
			<wfw:commentRss>http://ddayinc.com/wordpress2/20080804/new-vmware-vi-toolkit-10-fixes-connectivity-to-server-2-rc1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

