{"id":52,"date":"2007-01-21T07:00:00","date_gmt":"2007-01-21T15:00:00","guid":{"rendered":"http:\/\/testblog.sapien.com\/index.php\/2007\/01\/21\/make-a-cmdlet-part-6-wrapup\/"},"modified":"2007-01-21T07:00:00","modified_gmt":"2007-01-21T15:00:00","slug":"make-a-cmdlet-part-6-wrapup","status":"publish","type":"post","link":"https:\/\/dev.sapien.com\/blog\/2007\/01\/21\/make-a-cmdlet-part-6-wrapup\/","title":{"rendered":"Make-A-Cmdlet: Part 6, Wrapup"},"content":{"rendered":"<p><P>Okay, in my cmdlet code, you&#8217;ll notice that I used WMI &#8211; albeit in a very .NET-esque fashion &#8211; to ping a remote computer. That&#8217;s kind of my VBScript background talking; WMI is how I&#8217;d do the same task in VBScript. Well, it pays to investigate: Turns out .NET has a built-in functioning for pinging computers! I can change my cmdlet&#8217;s subroutine to be even simpler:<\/P><PRE>Protected Overrides Sub ProcessRecord()<BR>&nbsp;Dim ThisName As String<BR>&nbsp;For Each ThisName In _Name<BR>&nbsp; If My.Computer.Network.Ping(ThisName) Then<BR>&nbsp;&nbsp; WriteObject(ThisName)<BR>&nbsp; End If<BR>&nbsp;Next<BR>End Sub<\/PRE><P>This is a good example of how a little exploration can save you a lot of time coding. My entire cmdlet now consists of a property declaration and this subroutine &#8211; about a dozen lines of VB.NET code!<\/P><P>I also mentioned earlier that you could have been doing all this programming in PrimalScript 4.1 Enterprise. I&#8217;ve been using Visual Basic Express, which is a free, stripped-down&nbsp;edition of Visual Studio 2005; I did so mainly because there are templates available to get me started with a snapin and cmdlet. So where are the templates for PrimalScript? They&#8217;re coming :). I&#8217;ll use PrimalScript for future projects, in fact &#8211; after all, I already have it installed, and it takes up about a third the drive space that even the stripped-down Visual Basic Express does. On my laptop in particular, drive space is still at a bit of a premium (I&#8217;m an ultraportable guy &#8211; you can keep your 17&#8243; widescreen!).<\/P><P>So you&#8217;ve seen how to build a cmdlet. You may have noticed that I named my cmdlet &#8220;PrimalToys.&#8221; The name comes from a collection of COM objects that are included with PrimalScript (bet you didn&#8217;t know you had them &#8211; they&#8217;re documented in the <EM>PrimalScript 4.1: TFM<\/EM> manual, which is accessible from within the product&#8217;s Help menu). PrimalScript even includes an MSI-packaged version of PrimalToys (in the PrimalScript installation folder, under the Redist subfolder) so you can make the components available everywhere. PrimalToys seemed like a natural name for my PowerShell cmdlet package, then. Yes, <EM>package<\/EM> &#8211; you&#8217;ve only seen one, but I have about two-dozen in mind. Stay tuned, because I&#8217;m going to share the source code from this project as an attachment in a future post next week.<\/P><P>Technorati Tags:<BR><A href=\"http:\/\/technorati.com\/tags\/cmdlets\" rel=tag>Cmdlets<\/A><BR><A href=\"http:\/\/technorati.com\/tags\/powershell+development\" rel=tag>PowerShell Development<\/A><\/P><\/p>\n","protected":false},"excerpt":{"rendered":"<p><P>Okay, in my cmdlet code, you&#8217;ll notice that I used WMI &#8211; albeit in a very .NET-esque fashion &#8211; to ping a remote computer. That&#8217;s kind of my VBScript background talking; WMI is how I&#8217;d do the same task in VBScript. Well, it pays to investigate: Turns out .NET has a built-in functioning for pinging computers! I can change my &#8230;<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[2,25],"tags":[],"class_list":["post-52","post","type-post","status-publish","format-standard","hentry","category-general","category-windows-powershell"],"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/52","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/comments?post=52"}],"version-history":[{"count":0,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/posts\/52\/revisions"}],"wp:attachment":[{"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/media?parent=52"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/categories?post=52"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dev.sapien.com\/blog\/wp-json\/wp\/v2\/tags?post=52"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}