PowerShell Tip #1 from the Winner of the Advanced Category in the 2013 Scripting Games

In case you haven't heard, the 2014 Winter Scripting Games are just now getting started. Regardless of your skill level with PowerShell, it couldn't be a better time to participate since this is the first time in the history of the scripting games that you'll be able to work as part of a team and receive proactive feedback (before your code is judged) from a team of expert coaches who use PowerShell in the real world on a daily basis. Ultimately, the scripting games make learning PowerShell more interesting and challenging while giving you the opportunity to network with other enthusiasts in the industry.

Now it's time to talk about a PowerShell tip that I wanted to share.

Tip #1 - Read the Help!

While this may not be the most popular tip, believe it or not, it's one of the most important and it's something that's so simple it's often times overlooked. In my opinion, you'll never truly be effective with PowerShell and be able to figure things out for yourself until you learn to read the help.

I have an entire recorded presentation dedicated to the three core cmdlets that is titled PowerShell Fundamentals for Beginners if you would like more information about them:

1Get-Help
2Get-Command
3Get-Member

Don't assume that you know what a parameter does based on its name. The Invoke-Command cmdlet has a SessionName parameter that was added in PowerShell version 3.

I'll create a PSSession to a computer named DC01 and I'll name the session "dcSession":

1New-PSSession -ComputerName dc01 -Name dcSession

sg-tip1a.png

Without reading the help, it's plausible to think that you could use the PowerShell remoting Invoke-Command cmdlet along with its SessionName parameter specifying the name of the session that you just created as its value:

1Invoke-Command -SessionName dcSession {Get-Process}

sg-tip1b.png

Unfortunately, that wouldn't be correct. Why? Because you didn't read the help to find out what that particular parameter actually did before attempting to use it. If you had read the help first, you would have discovered that the SessionName parameter is only valid with the InDisconnectedSession parameter:

1Help Invoke-Command -Parameter SessionName

sg-tip1c.png

I'll now remove the PSSession that I previously created since it's no longer needed:

1Get-PSSession -Name dcSession | Remove-PSSession

sg-tip1d.png

You can also teach yourself about cmdlets that you didn't know existed or more about the ones you did by reading the help. One of the tips I wrote about in a guest article that I wrote for PowerShell Magazine was how to "learn a PowerShell cmdlet a day":

1Get-Command | Get-Random | Get-Help -ShowWindow

sg-tip1e.png

In addition to cmdlet help, PowerShell also has "about" help topics which contain information about various aspects of PowerShell such as concepts, keywords, scripting constructs, conditional logic, etc:

1help about_*

sg-tip1f.png

µ