views:

146

answers:

3

I'm early on in my PowerShell learning, and I'm wondering if there are some good guidelines for verbs in Posh for cmdlets (or advanced functions, whatever they're called in CTP3).

If I do a get-verb I can see the lot of them. But I'm still not sure how I should lay out my modules.

Here's the example I'm running into right now. I have a little script that asks Perforce: if I were to sync, what files would change and how big are they? It outputs a summary of sizes and a mini-tree of folders for where the changes will occur (as well as how many would need resolving).

Is that a query-p4sync? Or is it a 'sync-p4 -whatif'? Or something else?

Before I start writing a lot of these scripts I want to make sure I name them right.

+6  A: 

You can find a list of common verbs on MSDN along with a description what they should be used for.

Joey
Exactly what I needed, thank you.
Scott Bilas
Note however, that it still seems to be preliminary. For example, the verb Ping should be used over Test for determining whether something is alive and responding. However the current CTP of PS 2 includes a Test-Connection cmdlet (which is an equivalent of ping) which is named wrong according to those guidelines.
Joey
+4  A: 

Here's an updated list of approved verbs on the Windows PowerShell Blog, as of July 15.

Tyson Gilberstad
+2  A: 

From your use of the word "modules", I'm going to guess you are using V2 of PowerShell, which allows you to take advantage of Advanced Functions.

Advanced functions provide a way to attribute your function to provide native support for -WhatIf and -Confirm

function Sync-PerforceRepository()
{
  [cmdletbinding(SupportShouldProcess=$true)]
  param (...) #add your parameters
  Begin
  {
    #setup code here
  }
  Process
  {
    if ($pscmdlet.ShouldProcess($ObjectBeingProcessed,"String Describing Action Happening")
    {
      #Process logic here
    }
  }
  End
  {
     #Cleanup code
  }

}
Steven Murawski