blog: Thoughts on cmdlet design
This weekend I did a Powershell session at a codecamp in Philly. During my session I was reminded of a old blog post of mine and the discussion Gil and I had. I thought this would be a perfect post for TheExpertsCommunity. I would love feedback on your thoughts.
I wanted to make a case for using task based cmdlets instead of methods when designing Snapins. There have been several "Vendors" that have produced cmdlets for Powershell: Exchange, Citrix, VMWare, and IBM to name a few. Most have done very well here, but this is one thing I think the VMware team excelled at.
Here is the basic Goal
The thing to avoid: Depending on methods for object task.
Lets say we have a Car Object (class). The Car object has Properties like Make, Model, Color, TireCount, Size, and Type. We also have things we can do with a car like start , turn off, stop, turn, load, and unload.
We could approach this by creating a Car class with the set properties and methods. This may seem simpler, but it is not intuitive for your typical Admin. Your typical admin does not want to do this
Ideally from an Admin perspective a bunch of Task oriented cmdlets would be your best bet. Let’s assume you had these cmdlets instead of Methods:
I wanted to make a case for using task based cmdlets instead of methods when designing Snapins. There have been several "Vendors" that have produced cmdlets for Powershell: Exchange, Citrix, VMWare, and IBM to name a few. Most have done very well here, but this is one thing I think the VMware team excelled at.
Here is the basic Goal
Get-Something | Filter | Change-Something | Save-Something
The thing to avoid: Depending on methods for object task.
Here is an Example of what I mean
Get-Something | %{$_.DoSomething()}
Lets say we have a Car Object (class). The Car object has Properties like Make, Model, Color, TireCount, Size, and Type. We also have things we can do with a car like start , turn off, stop, turn, load, and unload.
We could approach this by creating a Car class with the set properties and methods. This may seem simpler, but it is not intuitive for your typical Admin. Your typical admin does not want to do this
Get-Car | ?{$_.Type -eq "MiniVan"} | %{$_.LoadPeople()} | %{$_.Start()} | %{$_.Turn("Right")} | %{$_.Stop()} | %{$_.UnLoadPeople()}
Ideally from an Admin perspective a bunch of Task oriented cmdlets would be your best bet. Let’s assume you had these cmdlets instead of Methods:
- Get-Car
- New-Car
- Remove-Car
- Start-Car
- Stop-Car
- Invoke-TurnCar
- Invoke-LoadCar
- Invoke-UnLoadCar
- Set-Car
This reads more like a sentence than script syntax.
Get-Car -Type "MiniVan" | Invoke-LoadCar | Start-Car | Invoke-TurnCar -Right | Stop-Car | Invoke-UnloadCar
tshell :: Apr.19.2009 :: Active Directory, All :: No Comments »

