This entry gives a quick overview about the PowerShell verbs to use when abstracting CRUD operations into PowerShell CmdLets. When creating modules with CmdLets or just CmdLets I often have to create wrapper around CRUD APIs. Suppose we want to create CmdLets around the “Thing” API. Normally I would then create 4 CmdLets:

  1. Create-Thing
  2. Read-Thing
  3. Update-Thing
  4. Delete-Thing

With PowerShell we have to take a different approach: Microsoft publishes and describes the list of Approved Verbs for Windows PowerShell Commands on MSDN grouping it into categories and describing the intended use of each verb. So for our “Thing” API we would have to use the following verbs.

  1. New-Thing: CREATE
  2. Get-Thing: READ
  3. Set-Thing: UPDATE
    Here “Set” might be be misunderstood to have a resource created when it does not exist. However it matches with the “Get” verb.
  4. Remove-Thing: DELETE

And this is actually the pattern we normally follow.

But Microsoft also allows for other verbs, so we could also use:

  1. Create-Thing: CREATE
  2. Read-Thing: READ
  3. Edit-Thing: UPDATE
  4. Delete-Thing: DELETE

Whatever you choose we should just try to have a consistent way of doing things. In my opinion “Edit” or “Update” better reflect the intended CHANGE operation, whereas “Get” and “Set” present a more “natural” programming style (and these are the names I use for our Cmdlets). And in case the “official” verbs are just not fitting for one instance we can always define an alias around that contains an “unofficial” combination of verbs (for example “Login-Thing” might seem easier to understand than “Enter-Thing”).

The choice is yours.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.