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:
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.
- New-Thing: CREATE
- Get-Thing: READ
- 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.
- Remove-Thing: DELETE
And this is actually the pattern we normally follow.
But Microsoft also allows for other verbs, so we could also use:
- Create-Thing: CREATE
- Read-Thing: READ
- Edit-Thing: UPDATE
- 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.