Unless you know the meanings of the five symbols regularly used in PowerShell, they can obscure the purpose and actions of a PowerShell script. There will always be new cmdlets to decipher. Each new operating system release and application version will include new and useful cmdlets along with new parameters for existing cmdlets. You can't memorize them all, but with the basic knowledge of these particular symbols, you should be well equipped to follow the logic of many scripts.
Recently, I had been asked to automate the creation of over one thousand new user accounts in the Active Directory® domain of one of my clients. This is a yearly process that had been done manually in the past, and it had required dozens of hours by administrative and IT staff members to get it done. When I mentioned that PowerShell could easily automate the process and avoid many of the errors you encounter with data entry done by hand, it was an easy choice for them. There was, however, a complaint that came after I had finished the script, executed it, and created all the accounts without a single error.
My direct contact at the company was their IT director. He said the problem was with the script. He loved the results of the script, but when he looked at the PS1 file (PS1 is the file extension that most PowerShell scripts use), it may as well have been written in Greek. Even after reading the comments that I had included in the script, he admitted that he just couldn't follow the syntax. I spent the next fifteen minutes walking him through the script line by line explaining what was happening at each stage.
Many people in IT fall into this same predicament. Since using PowerShell often comprises a small portion of what you may be responsible for doing, you don't learn its intricacies. In most cases, people google what they are looking for and download a script to do what they need. With good reason, however, they are reticent to execute a script on their network without a clear idea of exactly what it does. The skill you need is the ability to translate PowerShell into plain English!
The Five Symbols
There are five symbols that you will see regularly in PowerShell scripts. If you have experience with other scripting or programming languages, they may even be familiar to you. The purpose of this white paper is not necessarily to teach you how to use these symbols. Instead, our goal is to allow you to read and recognize them so that you can understand their meaning when they are used in existing scripts.
The five symbols and their basic meanings are:
@ hash table
| passes results of one command to the next command
$ indicates a variable
Some of these symbols are shortcuts used to condense a script; others are notations used to allow customized displays of information. The pipe (shift-backslash on your keyboard) allows you to join individual command-lets (cmdlets) together. They are all useful, but can easily lead to confusion due to their lack of obvious meaning when seen by an inexperienced reader.
Most commands in PowerShell are written as cmdlets and normally follow a verb-noun format. An example would be "Get-Service" with Get being the verb and Service being the noun. They are relatively easy to read and comprehend. The confusion arises when people use aliases which are accepted abbreviations for many commands. The alias for Get-Service is "gsv" and it returns the same results as the cmdlet. Many of the five symbols I mentioned earlier also act as aliases, so understanding their meaning can help to decode many scripts.
To see a complete list of these aliases, you can access PowerShell's alias drive.
PowerShell does allow you to add your own aliases, and they will be displayed in this list. Be aware, however, that the default behavior is that your aliases will only exist as long as you have this console open. Each time you open a new session, the aliases would have to be recreated.