PoshOnTap: Manage NetApp SAN from PowerShell Demo

Well it’s the night before VMworld, and I can’t sleep, so I’m catching up on my blog.  A while back I did a presentation to the PowerShell Virtual Users Group.  I demoed my PoshOnTap PowerShell Module, a lot has changed since that presentation.  Mainly I have a new version, but I’m still in the process of trying to get the nod from NetApp.  So in the meantime if you wished you could manage a NetApp SAN from PowerShell go check it out I have the first 30 minutes.  http://marcoshaw.blogspot.com/2009/08/windows-powershell-virtual-user-group.html

With a little luck I’ll get the nod to redistribute the manageontap c# assemblies, and I’ll post Version 2 of my PoshOnTap module!


PowerShell PSA: Stop Crunching the CODE!

Stop crunching the code people! I know PowerShell is incredibly powerful, and can be extremely terse, but seriously! Can someone explain to me how all this shorthand helps anyone?

I’m not condemning shorthand. Give me a fire and a PowerShell prompt my code is barely legible (and mostly red :D), but I don’t post that crap. This isn’t hard, when passing on knowledge to the community as a whole, or answering a post in a forum, clean it up!

There are already too many Admins intimidated by PowerShell. All this needless over complication isn’t helping! Your blog post may never get a comment, but your code is impacting the community as a whole.

Enough already, stop… crunching… the code.

PowerShell: Enough with the text files already

A note to all PowerShell enthusiast, PowerShell has made it, it’s on the map… A significant portion of that success is due to the power of the pipeline. It’s ability to act as the glue for any task.  Unfortunately, the  skill level required to implement this glue depends on the echo-system.  As a PowerShell enthusiast you are a member of this echo-system, and any code you write either helps or hurts this effort.  In short when posting code to the world show them what well written code looks like!  Writing a function that is hard set to read a list of servers from a text file is NOT good code!   Personally I think this should throw an error.

Okay so I don’t approve of reading from a text file, so what’s my solution?  Remove that part of the logic entirely!  There are literally hundreds (perhaps thousands) of techniques that could be used to retrieve data for any given operation.  leave the getting to the end user.  If you must get the data then show a more practical approach.  Seriously,  it’s Windows PowerShell after all, that list of computers… chances are they’re all running windows… and there is a high probability that they belong to a domain! In your examples highlight extracting the data from AD.  After all would you really use static data in one of your scripts?

If you just can’t use the quest cmdlets use ADSI anything but a text file. Another one of my favorites is importing a list of IP Addresses.  I know it’s incredibly easy to create a list of IP Addresses in Excel, but is that really the lesson?  Hey PowerShell is the most important thing since the mouse, but if you need 254 concurrently numbered IP’s get Excel…  just add the code

Even better highlight why it’s so important to always emit object.  Show the benefit of such an approach.

I know, I know it’s all been done before.  I know we already had the why you should emit object discussion, and the foreach construct vs foreach-object cmdlet debate, etc… believe it or not the community has grown ten fold since those discussion’s where closed.  While I don’t want to constantly rehash this stuff… I’m asking that we don’t perpetuate the problem by using BAD techniques when we know better.

If you don’t have time just omit it.   Hide that part from the point of the post.  There is nothing wrong with

After all the do-something is the important part!  Just leave populating $servers to someone else… Why does this matter?  Simple, you never know what someone will learn from your code.  I read PowerShell post all the time, and I am constantly learning something new.  Just not always what the author intended.  The point of post x was to teach me how to use widget x from PowerShell.  Only I found this $? thing (what is that, and what does it do?)…   The next guy finds the same post via google because there trying to figure out the foreach construct, and bamn that get-content server.txt just became part of his repertoire.  Chances are he never even got to the part for widget x.  Moral of the story it’s better to omit part of the solution then to publish a poor answer.

Another penalty imposed by this hard coded methodology is it totally breaks the has-a model PowerShell was built around.  requiring a text file with a list of server names is the text book definition of the is-a model.  lamen terms by hard coding such a critical portion of your code… by importing data from a file you limit the flexibility of  your code.

It’s not all bad though, a couple years ago there where 10 guys.  Ten people who taught all of us how to use PowerShell.  Today there are 10 new PowerShell bloggers every day, and it appears that every team in Redmond (except SCCM) has PowerShell on it’s road map. I’m not trying to be the code police, but can we at least loose the text files?


10th Powershell virtual usergroup announced

UPDATE: Due to a schedualing conflict the meeting has been moved to Thursday May 7th, 2009 at 8:00PM EST (lucky number 7 should be a good meeting)

Marco announced yesterday that the 10th Powershell Virtual User group will be held on Thursday April 30th, 2009 at 8:00PM EST.  On the schedule will be Bart De Smet (Microsoft), Sergei Anotonov (Microsoft), and Your’s truely!

I will be presenting Managing NetApp via Powershell, and plan on covering the OnTap SDK as well as my own PoshOnTap V2 module.

All the details can be found here

See you there

PowerShell: Ping-Subnet

A couple a weeks ago I was hanging out in the PowerScripting Ustream waiting for the show to start. There were several of us caring on, when the interview subject Brandon Shell placed a call to scripting. He asked for a script to ping a subnet. There are many select-alive/ping-host scripts why write another one? The answer is simple pinging a target is easy, what Brandon was asking for was a fast way to generate the list of hosts. (Additionally, if you work with Active Directory then you can already see the usefulness in being able to ingest the subnets in sites and services as a parameter.) Shortly after Brandon made the request I opened my big mouth, and commented that the math was easy. The hard part is “threading”, as you know we can’t thread in PowerShell… but there are ways to perform concurrent operations. The PSJobs in V2 were purpose built for such a task. Unfortunately the *-job cmdlets use winrm as a backend, and require WS-MGMT to be installed/configured. As I was carrying on with this line of thought Brandon broke in, and informed me that the Get-WMIObject cmdlet in CTP3/V2 uses its own ‘backend’! He went on to inform me that all I needed was to tack on the –AsJob parameter… After a couple quick tests, I had a draft, and shortly thereafter a script!

Read more

Powershell: Passthru Authentication with OnTap SDK 3.5

This morning I decided to play with the passthru authentication via RPC that the SDK provides, and boy is it easy! To utilize passthru authentication you first you need to install a dll. Assuming the sdk is saved to C:

copy “C:manage-ontap-sdk-3.5libntntapadmin.dll” %windir%System32ntapadmin.dll
copy “C:manage-ontap-sdk-3.5libntx64ntapadmin.dll” %windir%System32ntapadmin.dll
copy “C:manage-ontap-sdk-3.5libntntapadmin.dll” %windir%SysWOW64ntapadmin.dll
copy “C:manage-ontap-sdk-3.5libntia64ntapadmin.dll” %windir%System32ntapadmin.dll
copy “C:manage-ontap-sdk-3.5libntntapadmin.dll” %windir%SysWOW64ntapadmin.dll

Now that the appropriate DLL is installed connecting to a Filer is as simple as specifiying the style as RPC.

Similar procedures will enable the SLL/encryption capabilities within the SDK only using the ssleay32.dll(SSL)/libeay32.dll(encryption). I’m not yet sure what the zephyr(ZAPI) assemblies do, but hey I’m just admin living in a devs world.


PoshOnTap: Monitor reconstruction status

Well this morning I had the distinct privilege of loosing two disks… YIKES! Thank’s to Raid_DP my Aggregate is still online, but if I loose another disk I’m done. As this is not a comfortable position to be in I want to know how long it will take; enter PowerShell!

Using my PoshOnTap module I wrote a quick script to monitor the status of a rebuild. Hopefully you’ll never need it!

Read more

Powershell: PoshOnTap meet world…

UPDATE: This project has been moved to codeplex, the latest build can be located here.

Okay… well I’ve written enough, and tested what I can… Time to let this baby go and see what happens!   PoshOnTap released!

What is PoshOnTap?  PoshOnTap is a collection of PowerShell V2 Advanced Functions to manage A NetApp Filer from PowerShell.  All in all the project contains 138 cmdlets covering everything from basic disk management to snapvaults and everything in between!

What isn’t PoshOnTap? PoshOnTap is not in anyway affiliated with NetApp… I wrote it, and I’m sure there are bugs!!!  I’ve tried my best to polish it all up, but at the end of the day use with caution…. i.e., if you break your production SAN, I don’t want to hear about it!  Additionally two glaring holes are the lack of cifs/NFS/FC cmdlets… I’ve been writing this for six months, and 20k + lines of code later I still haven’t gotten to them. I decided that if I tried to do it all in one swipe OnTap 8 would be released before I could finish.

The framework is very basic anything can be accomplished with the use of one class and a cmdlet, everything else is a wrapper to ease the administrative experience.

How to use:

  1. Download the source files from below, and extract to a location on your local machine.
  2. If your running all-signed you’ll need to sign the scripts prior to execution (sorry I can’t afford a code signing cert)
  3. from a Powershell V2 CTP3 prompt type: Import-Module <path>PoshOnTap.psd1

There is a short getting started doc to give you a rough idea, but this is all very raw…  My hope is that the community can pick this up, and bring it all that last mile.  Adam provided the idea with Powershell OnTap, and I hope I’ve provided a base!   I will blog some example uses next week, but in the interim.

Have at it!


UPDATE: this project has been superceeded by it’s big brother PoshOnTap v2 www.codeplex.com/poshontap

Read more

PowerShell: Format-Comments

I’ve been writing a TON of CTP3 advanced functions in the last month, and so far my favorite feature is in-line help.  The ability for me to place proper PowerShell  help files in a script… epic!  Having said that, formatting everything down to 80 char lines… is a pain in the ares.  This morning I had enough and wrote a quick filter to handle it all for me.