How should I name my PowerShell Scripts?

Home > Blogs > PowerShell > How should I name my PowerShell Scripts?

How should I name my PowerShell Scripts?

1 0 Jason Helmick
Added by July 25, 2011

I get this question a lot, and just recently on the Windows PowerShell Forum on Technet.

Now let’s talk about this for a minute. If you're one of those people wondering what the answer is, you will see many answers that may confuse you further. The most common response is “put your stuff into a module”.

Modules are scripts that contain Advanced Functions. Basically, when someone tells you to make a “module”, they are saying to build all of your scripts into cmdlets using Advanced Functions, then store them in a special script that has a .psm1 extension.

This is a good answer because now your cmdlets are very portable (just copy the module) and easy to import and use.

The bad part of this answer is you have to know what an Advanced Function is, how to make modules, and how to write your script into an Advanced Function. It’s not easy if you're just starting out with PowerShell.

To be honest, I’m a big fan of Advanced Functions and Modules, but not as a solution to this problem.

Scripts Are Good
Many people starting out with PowerShell are not “Tool Makers” that would make modules. Many of them are writing small scripts to get things done. I write scripts all the time that should not be turned into cmdlets. So, If you're like me or just getting started with scripting in PowerShell, what do you do if you don’t want to make a module, but still need to organize your scripts?

Simple. Use PowerShell to help you.

How to name your PowerShell Scripts
All PowerShell cmdlets are named with a verb-noun. When you use Get-Command, it lists them alphabetically.

All PowerShell cmdlets are named with a verb-noun. When you use Get-Command, it lists them alphabetically.

Over time, you get used to seeing everything as a verb-noun listed alphabetically.  So don’t fight it.  Name your scripts the same way.

The super guru MVP of PowerShell Don Jones just recently wrote about this.  He is correct.  So, here is how I name my scripts.

1. Use the same verbs that Microsoft uses for the cmdlets.  The reason is simple, you need to be consistent so everyone understands what the script will do.  At a PowerShell prompt, type Get-Verb and choose the best verb for what the script does.  While there are many choices, you’re best to stay in the “Common” ones if possible.

Windows PowerShell Get Verb for Script

PowerShell Get Verb for Script

2. Choose the noun. This is totally up to you, but the idea is to specify “what” will be affected. As an additional note, the cool people only use the singular of the noun. It’s not “Get-Services”, it’s “Get-Service”.

3. Put a dash in between the verb and the noun! Yup, just like the cmdlet’s.

4. Put all of them into a folder. Don’t go nuts here and start to create a bunch of sub folders. I find that Admin’s are anal-as-hell and want to over organize everything. The point to naming the scripts like a cmdlet is that they will automatically organize themselves and provide a similar view like Get-Command.

5. Don’t believe me, try it!

Here is a Windows Explorer view of a sample directory.

Windows Explorer view of PowerShell scripts named like cmdlet Windows Explorer view of PowerShell scripts named like cmdlet

Here is a PowerShell view.

Windows PowerShell script organized

Isn’t that much easier to organize your scripts? After years of working with Admins, I find this keeps things simple and easy to find. It’s also very portable and easy to copy. DON’T COMPLICATE THIS!

The beauty of how the PowerShell Team designed the cmdlet naming can be put to use with your script naming as well. Don’t look for “Graphical Script Repositories” and the such. Use what you already know and keep the solution simple for everyone!

Knowledge is PowerShell

Videos You May Like

A Simple Introduction to Cisco CML2

0 3661 0

Mark Jacob, Cisco Instructor, presents an introduction to Cisco Modeling Labs 2.0 or CML2.0, an upgrade to Cisco’s VIRL Personal Edition. Mark demonstrates Terminal Emulator access to console, as well as console access from within the CML2.0 product. Hello, I’m Mark Jacob, a Cisco Instructor and Network Instructor at Interface Technical Training. I’ve been using … Continue reading A Simple Introduction to Cisco CML2

Configuring Windows Mobility Center and How to Turn it On and Off

1 1404 1

Video transcription Steve Fullmer: In our Windows training courses, we often share information about the Windows 8.1 Mobility Center. Mobility Center was introduced for mobile and laptop devices in Windows 7. It’s present and somewhat enhanced in Windows 8. Since we don’t have mobile devices in our classrooms, I decided to take a little bit … Continue reading Configuring Windows Mobility Center and How to Turn it On and Off

OSPF Adjacency Troubleshooting Solution – Getting Close to the OSPF adj

0 246 1

In this video, Cisco CCNA & CCNP instructor Mark Jacob shows how to troubleshoot OSPF Adjacency issues by showing the distance between routers with the show ip ospf neighbor command.

Write a Comment

Share your thoughts...

Please fill out the comment form below to post a reply.