What is the naming convention for Powershell functions regarding the use of upper / lower case?

Although I found a lot of information on how to name cmdlets and functions in the Cmdlet Design Guide , I did not find any information on whether functions should be named in upper or lower case.

What is a convention here?

(I understand that the cmdlets themselves are usually named in uppercase, even if they are not case sensitive when it comes to execution.)

+10
powershell naming-conventions
source share
2 answers

Naming convention can be tricky. Although a fixed naming convention may provide aesthetics or simplified use, this is not required. In general, the naming convention I advocate for is the one already in use in Powershell. Since functions are created on the basis of a noun verb, each word begins with a capital letter or, if it is an abbreviation, all capital, or if it is property, then, as well, respectively.

For example, I created some functions for myself:

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

You can imagine what these functions do, it's pretty clear, straightforward, and compatible with Powershell's built-in functions. However, I have exceptions to the โ€œimportโ€ of several Unix commands into Powershell (for example, killall , pidof , etc.). You can always use Set-Alias if you want to write something else.

This issue, no matter how important it may be, can be discussed, since there seems to be no โ€œone, better wayโ€. All this, in the end, depends on personal preferences.

+15
source share

The function is basically a script based cmdlet. The cmdlet is written, for example. C #, and the function is written as a script. Because of this similarity, I recommend that you use the same style as cmdlets for your "stand-alone functions" so that it is part of other PowerShell cmdlets. Ex. I had a filecount function (for each folder) that I often used. I called it Get-FileCount .

However, I usually call helper functions (functions that you use only in other functions) using a simpler name like convertsidtousername , etc.

You can use aliases to create short names for the function.

0
source share

All Articles