Chapter 4. The basics of PowerShell syntax

 

This chapter covers

  • Using commands in PowerShell
  • Using command parameters
  • Working with command aliases
  • Using script blocks

Any time you’re learning to use a new tool, particularly one that involves typed commands, the syntax can be the biggest “gotcha.” We won’t pretend that every single bit of PowerShell’s syntax is easy to remember, makes perfect sense, and is totally consistent. In the end, the syntax is what it is—we (and you) have to learn it and deal with it.

If you’ve used PowerShell a bit already, and if you’ve picked up some of its syntax from reading other people’s blogs and articles on the internet, you may have an inaccurate view of the syntax. You also need to remember that best practice has evolved over the five-plus years we’ve had between the original release of Power-Shell and the latest version. This chapter will help set you straight.

4.1. Commands

PowerShell has four features that we think of as commands:

  • Internal cmdlets, which only run inside PowerShell and are written in a .NET Framework language such as Visual Basic or C#
  • Functions, which are written in PowerShell’s scripting language
  • PowerShell v3 cmdlets, which are produced from WMI (Windows Management Instrumentation) classes using the “cmdlets over objects” capabilities
  • External commands, such as ping.exe, which could also be run from the old cmd.exe shell

In this chapter, we’ll focus only on the first two command types.

4.2. Parameters

 
 
 
 

4.3. Typing trick: line continuation

 
 
 

4.4. Parenthetical commands and expressions

 

4.5. Script blocks

 
 
 

4.6. Summary

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest