Scripting Games 2013: Naming Conventions for Functions and Scripts

My last post of the night. While reviewing scripts, I have seen multiple entries that are something like the following:

  • Move-LogFiles
  • Move-ApplicationLogs
  • Move-Files
  • MoveFile

What is the problem with this you ask? Well, for starters, there are no plural nouns with function names. Run this command and let me know how many plural nouns you find.

Get-Command -CommandType cmdlet | Select -Unique Noun

It should be 0. When creating a function or even naming a script, you should take care in naming it using a Verb-SingularNoun format to keep in line with PowerShell best practices such as Move-LogFile or Move-ApplicationLog.

Also keep in mind the verbs as well. You can find all legal verbs using the following command:

Get-Verb

Use any of the Verbs listed and you can’t go wrong (unless the verb being used is completely different than its intended purpose!).

About Boe Prox

Microsoft Cloud and Datacenter MVP working as a SQL DBA.
This entry was posted in 2013 Scripting Games Judges Notes, Scripting Games 2013, Tips and tagged , , , . Bookmark the permalink.

2 Responses to Scripting Games 2013: Naming Conventions for Functions and Scripts

  1. Pingback: Scripting Games 2013: Thoughts After Event 1 | Learn Powershell | Achieve More

  2. GaryJ says:

    Guilty! Changed my script from move-logs to move-log. Thanks for the info!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s