Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What the Cmdlet Development Guidelines say about case use for functions in Cmdlets?

Tags:

powershell

While I did find a lot of information on how to name Cmdlets and functions in the Cmdlet Development Guidelines I did not find any information on whether functions should be named in upper or in lower case.

What is the convention here?

(I do understand that Cmdlets themselves are generally named in upper case, even though they are not case-sensitive when it comes to executing.)

like image 990
mthomas Avatar asked Jul 22 '14 08:07

mthomas


People also ask

What is the function of this cmdlet?

A cmdlet -- pronounced command-let -- is a small, lightweight command that is used in the Windows PowerShell environment. A cmdlet typically exists as a small script that is intended to perform a single specific function such as coping files and changing directories.

Which of the following is true about PowerShell cmdlets usage?

Parsing, error presentation, and output formatting are not handled by cmdlets. It is done by the Windows PowerShell runtime. Explanation: All of the above is true about Cmdlet.

What is the difference between cmdlet and function in PowerShell?

A cmdlet is a single command that participates in the pipeline semantics of PowerShell. This includes binary cmdlets, advanced script functions, CDXML, and Workflows. Advanced functions allow you create cmdlets that are written as a PowerShell function.

What are two important characteristics of a cmdlet?

The building blocks of Powershell: cmdlets The three most important characteristics are: Cmdlets output results as an object or as an array of objects. Cmdlets can get data for analysis or transfer data to another cmdlet using pipes. Cmdlets are case-insensitive.


1 Answers

Naming convention can be tricky. While a fixed naming convention may provide aesthetics or simplified usage, it is not required to be followed. In general, a naming convention that I advocate for is the one that is used already in Powershell. As functions are created on verb-noun base, each word starts with a capital letter or if it is an abbreviation - all capitals, or if it is a proprietary - then as it is accordingly.

I have, for example, created some functions for myself:

Get-ServerDiag
Mount-TrueCryptVolumes
Start-RDP
Generate-RandomPassword
Nuke-Environment

You can imagine what these functions do, it is rather clear, straightforward and compliant with built-in Powershell functions. I do however have exceptions which come from "importing" a several Unix commands to Powershell (like killall, pidof etc...) You can always use a Set-Alias if you prefer to write something else.

This question, however important, is discussable as there does not seem to be the 'one, best way'. It is all, in the end, up to personal preferences.

like image 200
AlexPawlak Avatar answered Oct 15 '22 20:10

AlexPawlak