liveBook · Manning

Chapter 19: You call this scripting?

What you will learn in chapter 19 of Learn PowerShell in a Month of Lunches: Fourth Edition, Covers Windows, Linux, and macOS

The introduction contrasts what administrators can accomplish at the PowerShell command line with the reason to start using simple scripts: avoiding repeated typing.

After this chapter you will be able to

What it builds on

Section by section

Introduction

The introduction contrasts what administrators can accomplish at the PowerShell command line with the reason to start using simple scripts: avoiding repeated typing.

Key terms: command-line interface, scripts, scripting

19.1 Not programming, more like batch files

This section presents a PowerShell script as an ordered list of commands and shows how to create one in VS Code.

Key terms: script, batch file, PowerShell scripts, VS Code, Run button, Save

19.2 Making commands repeatable

The section turns a reusable command into a saved PowerShell script and shows how to format and test it in VS Code.

Key terms: script, Get-DiskInventory.ps1, cmdlet-style verb-noun names, pipe character, parameter names, positional parameters, Run toolbar icon, F5, F8

19.3 Parameterizing commands

The section shows how to prepare a repeatable command for changing inputs by replacing fixed parameter values with variables, then explains how to split long commands across lines.

Key terms: -computername, $computername, -path, $filepath, localhost, backtick, pipe symbol, pipeline

19.4 Creating a parameterized script

This section shows how to turn hardcoded script values into parameters and run the script with positional or named arguments.

Key terms: Param() block, input parameter, default value, $computername, named, positional, parameter name abbreviation, .\, -drivetype, -computername

19.5 Documenting your script

The section shows how to put PowerShell help in script comments and view it with the normal help command.

Key terms: comment-based help, #, <# #>, .DESCRIPTION, .SYNOPSIS, help, -full, script path

19.6 One script, one pipeline

Explains why two commands can display differently when run in a script rather than individually, and why scripts should generally output one kind of object.

Key terms: pipeline, script, pipeline output, Process objects, TimeSpan objects, formatting system, Out-Default, Out-Host

19.7 A quick look at scope

Explains how PowerShell scopes contain and resolve names, how script scope differs from global scope, and how to avoid relying on values outside a script.

Key terms: scope, global scope, script scope, current scope, parent scope, Param() block, parameters

19.8 Lab

Where this is used later

Concepts explained in this chapter

← Chapter 18: Sessions: Remote control with less work Chapter 20: Improving your parameterized script →

These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.