Chapter 3. PowerShell’s scripting language

 

Before we dive into scripting and toolmaking, we need to cover a few background concepts—some of which are unique to PowerShell. We’re also going to do a lightning overview of PowerShell’s scripting constructs. If this seems a bit brief, don’t worry—we’ll be re-explaining a lot of these when you see them in a more practical context. The idea now is to familiarize you with what’s ahead.

3.1. One script, one pipeline

A PowerShell script isn’t exactly like a command-line batch file, and running a script isn’t precisely the same as running the same commands yourself in the same sequence. For example, open a console window and run the following, pressing Enter after each line:

Get-Service
Get-Process

Now type those exact same lines into a script file, or into the ISE’s script editing pane, and run the script. You’ll get different results.

3.2. Variables

3.3. Quotation marks

3.4. Object members and variables

3.5. Parentheses

3.6. Refresher: comparisons

3.7. Logical constructs

3.8. Looping constructs

3.9. Break and Continue in constructs

3.10. Lab

sitemap