Chapter 4: Running commands
The introduction positions running commands as the beginner’s starting point for PowerShell, despite the advanced scripting examples often found online.
After this chapter you will be able to
- Command-first PowerShell starting point. Explain why beginners should not assume they must start by scripting or programming in PowerShell: even experienced users began by running commands.
- Existing permissions in PowerShell. Explain that PowerShell adds no permissions and does not bypass existing ones: a command or script can do only what the person running it is already permitted to do.
- Purpose of script security. Distinguish running permitted commands from being tricked into running a script, and explain why PowerShell's security focuses on unintentional script execution rather than stopping a determined user.
- Execution policy scope and defaults. Explain that execution policy governs which scripts PowerShell will execute, not whether users can run commands interactively, and describe the platform defaults given here.
- Script permissions by policy setting. Distinguish what Restricted, AllSigned, RemoteSigned, Unrestricted, and Bypass permit, including how RemoteSigned treats downloaded scripts.
- Execution policy configuration overrides. Describe how to inspect and change execution policy, and explain how Group Policy and the PowerShell.exe command-line switch affect a local setting.
- Execution policy security limits. Explain why execution policy is meant to prevent accidental script execution rather than stop an informed user or attacker.
- Interactive command workflow. Explain how a beginner typically uses PowerShell as a shell: type a command, add parameters to customize it, press Enter, and see the result immediately.
- Commands becoming reusable scripts. Describe how repeatedly used PowerShell commands can become a script and what running that script does.
- Full-form command components. Describe how the example command combines a cmdlet name with named parameters, values, a comma-separated list, and a switch parameter.
- Command typing rules. Explain the spacing, dash, quotation, and case rules illustrated by the example command.
- Verb-noun naming and discovery. Explain the standard verb–singular-noun pattern for cmdlets and how it helps you guess and verify command names.
- Command name aliases. Explain that a PowerShell alias is a shorter name for a command, such as gps for Get-Process, and that using it does not change the command’s parameters or behavior.
- Command and parameter shortcuts. Distinguish aliases, which are shorter versions of command names, from shortcuts that can be used with parameters.
- Unique parameter name prefixes. Explain that a parameter name can be shortened only to a prefix that uniquely identifies it among the available parameters, and describe how Tab can finish the name after that prefix is typed.
- Parameter aliases and discoverability. Explain that a parameter can have an alias, such as -ea for Get-Process’s -ErrorAction parameter, and describe what Tab completion and command help do—and do not—show about it.
- Recognizing positional parameters. Explain how command help identifies positional parameters, including what position 0 means.
- Unnamed parameter values and order. Describe how to supply values without positional parameter names and what ordering constraint that creates.
- Named parameters for lasting commands. Justify the recommendation to include parameter names in commands that will persist.
- Familiar external utilities. Explain that PowerShell can run existing command-line utilities on Windows, Linux, and macOS, even when a native cmdlet offers another way to do the job.
- External command parsing workaround. Describe why an external command with many parameters may fail in PowerShell and how placeholders and the invocation operator can help run it.
- Stop parsing marker tradeoff. Explain how the --% marker helps pass text to an external utility and why it cannot be used when parameter values must come from variables.
- Resolving confusing command errors. Describe how to troubleshoot an error that does not seem to match what you typed, using the Get-ChildItem example.
- Cmdlet name spelling. Explain that a cmdlet name is typed as verb-noun, such as Get-Content, with a hyphen rather than a space or another separator.
- Parameter dashes and spacing. Explain how to separate a cmdlet, its parameters, and any parameter values when typing a command, and distinguish these requirements from PowerShell’s usual indifference to capitalization.
What it builds on
- Parameter values (chapter 3) · Builds on interpreting parameter values in command help.
- Using help to find commands (chapter 3) · Using help to find commands.
- Asking for help (chapter 3) · Asking PowerShell for command help
- Parameter sets and common parameters (chapter 3) · Introduces parameters and common parameters in command help.
- Positional parameters (chapter 3) · Reading positional-parameter information in command help
- Interpreting the help (chapter 3) · Using command help to check how parameters are written.
Section by section
Introduction
The introduction positions running commands as the beginner’s starting point for PowerShell, despite the advanced scripting examples often found online.
- Command-first PowerShell starting point: Explain why beginners should not assume they must start by scripting or programming in PowerShell: even experienced users began by running commands.
Why it matters: You can start using PowerShell without first learning to write scripts.
Key terms: running commands, command-line utilities, scripting, programming
4.1 Let’s talk security
This section explains how PowerShell relates to existing permissions and why its security measures focus on unintentional script execution.
- Existing permissions in PowerShell: Explain that PowerShell adds no permissions and does not bypass existing ones: a command or script can do only what the person running it is already permitted to do.
Why it matters: This helps you predict whether a command or a script deployed to other users can perform an action. - Purpose of script security: Distinguish running permitted commands from being tricked into running a script, and explain why PowerShell's security focuses on unintentional script execution rather than stopping a determined user.
Why it matters: It clarifies what PowerShell's script protections are—and are not—meant to accomplish.
Key terms: permissions, command, script, PowerShell’s security system, unintentionally, scripts from untrusted sources
4.1.1 Execution policy
This subsection explains which scripts PowerShell’s execution policy permits, how the policy is set, and why it should not be treated as a security barrier.
- Execution policy scope and defaults: Explain that execution policy governs which scripts PowerShell will execute, not whether users can run commands interactively, and describe the platform defaults given here.
Why it matters: It explains why a command can work even when running a script is blocked. - Script permissions by policy setting: Distinguish what Restricted, AllSigned, RemoteSigned, Unrestricted, and Bypass permit, including how RemoteSigned treats downloaded scripts.
Why it matters: The setting determines whether a particular local or downloaded script can run. - Execution policy configuration overrides: Describe how to inspect and change execution policy, and explain how Group Policy and the PowerShell.exe command-line switch affect a local setting.
Why it matters: It helps explain why changing a local setting may have no effect. - Execution policy security limits: Explain why execution policy is meant to prevent accidental script execution rather than stop an informed user or attacker.
Why it matters: It prevents misplaced confidence in execution policy as protection against malicious users. - Recommended script policy balance: State Microsoft’s recommended choice when scripts must run and explain its convenience-versus-restriction trade-off.
Why it matters: It gives a practical starting point without portraying the policy as complete security.
Key terms: execution policy, Restricted, scripts, AllSigned, RemoteSigned, Unrestricted, Bypass, digital signature, Get-ExecutionPolicy, Set-ExecutionPolicy
4.2 Not scripting, but running commands
This section presents PowerShell as a shell where beginners can work effectively by running commands, then save repeated commands as scripts when useful.
- Interactive command workflow: Explain how a beginner typically uses PowerShell as a shell: type a command, add parameters to customize it, press Enter, and see the result immediately.
Why it matters: You can start getting useful results without first learning to write programs. - Commands becoming reusable scripts: Describe how repeatedly used PowerShell commands can become a script and what running that script does.
Why it matters: Saving commands you have already worked out makes repeated tasks easier. - Optional scripting complexity: Distinguish PowerShell's capacity for complex programming from the level of complexity needed to use it effectively as a beginner.
Why it matters: You can focus on useful command-line skills now and take on more complexity if you need it later.
Key terms: shell, command, parameters, .ps1, PowerShell script, scripts
4.3 The anatomy of a command
This section breaks down a full-form PowerShell command and explains the typing rules for its name, parameters, and values.
- Full-form command components: Describe how the example command combines a cmdlet name with named parameters, values, a comma-separated list, and a switch parameter.
Why it matters: Recognizing each part helps you read and construct commands without mistaking a switch for a parameter that needs a value. - Command typing rules: Explain the spacing, dash, quotation, and case rules illustrated by the example command.
Why it matters: Careful spacing and dashes prevent avoidable command errors.
Key terms: full-form syntax, cmdlet name, parameter name, switch parameter, parameter names, dash (-), quotation marks, case sensitive
4.4 The cmdlet naming convention
Defines PowerShell command terminology and explains how the verb-noun naming convention helps readers find cmdlets.
- PowerShell command terminology: Distinguish cmdlets, functions, and applications, and explain how the book uses command as an umbrella term.
Why it matters: These distinctions clarify what the book means when it refers to a cmdlet rather than a command generally. - Verb-noun naming and discovery: Explain the standard verb–singular-noun pattern for cmdlets and how it helps you guess and verify command names.
Why it matters: The pattern gives you a practical way to find commands without looking up every name from scratch.
Key terms: cmdlet, function, application, command, verb-noun naming convention, Get-Verb, Help, Get-Command, wildcards
4.5 Aliases: Nicknames for commands
This section explains how PowerShell aliases shorten command names, how to identify them, and why custom aliases require care.
- Command name aliases: Explain that a PowerShell alias is a shorter name for a command, such as gps for Get-Process, and that using it does not change the command’s parameters or behavior.
Why it matters: Aliases save typing without requiring you to learn a different set of parameters. - Alias identification through help: Describe how asking PowerShell for help about an unfamiliar alias reveals the full command name.
Why it matters: You can decipher an unfamiliar alias without memorizing built-in aliases. - Custom alias limits: Explain that custom aliases last only for the current shell session unless exported for later use, and why the authors avoid relying on them when sharing commands. Distinguish PowerShell aliases from Bash aliases that include parameters.
Why it matters: These limits help you avoid commands that work only in your session or are unclear to other people.
Key terms: alias, gps, Get-Process, help system, full command, New-Alias, Export-Alias, Import-Alias, custom aliases, Bash
4.6 Taking shortcuts
Introduces parameter shortcuts as another form of PowerShell shorthand alongside command aliases.
- Command and parameter shortcuts: Distinguish aliases, which are shorter versions of command names, from shortcuts that can be used with parameters.
Why it matters: This distinction helps you recognize shorthand when reading other people’s PowerShell examples.
Key terms: aliases, parameters, shortcuts
4.6.1 Truncating parameter names
Explains when a PowerShell parameter name can be shortened and how Tab completion makes that shortcut clearer.
- Unique parameter name prefixes: Explain that a parameter name can be shortened only to a prefix that uniquely identifies it among the available parameters, and describe how Tab can finish the name after that prefix is typed.
Why it matters: You can type less without leaving an ambiguous or hard-to-read parameter name.
Key terms: parameter names, minimum-length parameter, Tab
4.6.2 Using parameter name aliases
This subsection shows that parameters can have aliases and explains why those aliases can be hard to discover.
- Parameter aliases and discoverability: Explain that a parameter can have an alias, such as -ea for Get-Process’s -ErrorAction parameter, and describe what Tab completion and command help do—and do not—show about it.
Why it matters: Recognizing an alias helps you understand a short parameter name even when help shows only its full name.
Key terms: parameter aliases, -ea, -ErrorAction, Tab completion, common parameters
4.6.3 Using positional parameters
This section shows how to recognize and use positional parameters, then explains why named parameters are usually clearer.
- Recognizing positional parameters: Explain how command help identifies positional parameters, including what position 0 means.
Why it matters: Help can tell you where a value belongs when you omit its parameter name. - Unnamed parameter values and order: Describe how to supply values without positional parameter names and what ordering constraint that creates.
Why it matters: Leaving names out saves typing only if you keep the values in their required places. - Named parameters for lasting commands: Justify the recommendation to include parameter names in commands that will persist.
Why it matters: Explicit names make a saved command easier for someone else—or your future self—to read.
Key terms: positional parameters, position 0, full help, named (nonpositional) parameters, positional (unnamed) parameters, parameter names, PowerShell script file
4.7 Support for external commands
This section shows that PowerShell can run familiar external utilities, explains why some commands need help with parsing, and gives two ways to pass their arguments.
- Familiar external utilities: Explain that PowerShell can run existing command-line utilities on Windows, Linux, and macOS, even when a native cmdlet offers another way to do the job.
Why it matters: You can keep using tools you already know while choosing PowerShell cmdlets when their added capabilities help. - External command parsing workaround: Describe why an external command with many parameters may fail in PowerShell and how placeholders and the invocation operator can help run it.
Why it matters: This pattern gives you a way to run an external utility when PowerShell misreads its arguments. - Stop parsing marker tradeoff: Explain how the --% marker helps pass text to an external utility and why it cannot be used when parameter values must come from variables.
Why it matters: The shorter workaround is useful when you can supply values directly, but its variable limitation affects which approach you choose.
Key terms: external command-line utilities, cmdlets, Test-Connection, ping, parser, placeholders, invocation operator (&), --%, variables, parameter values
4.8 Dealing with errors
This section shows how to interpret PowerShell error messages and troubleshoot confusing ones by checking help and spelling out commands and parameters.
- Reading PowerShell error messages: Explain how an error message can point to where PowerShell ran into trouble, using the mistyped Get-Command example.
Why it matters: The error text can give you a starting point for finding a typing mistake. - Resolving confusing command errors: Describe how to troubleshoot an error that does not seem to match what you typed, using the Get-ChildItem example.
Why it matters: Spelling out the command can reveal a syntax mistake that the error message does not make obvious.
Key terms: error messages, Get-Command, help, Get-ChildItem, -Path, -Recurse
4.9 Common points of confusion
Introduces the chapter’s common-mistakes section as a way to help readers avoid or resolve problems when using PowerShell.
4.9.1 Typing cmdlet names
This section clarifies that cmdlet names must be typed with a hyphen between the verb and noun, even though the hyphen is often omitted in speech.
- Cmdlet name spelling: Explain that a cmdlet name is typed as verb-noun, such as Get-Content, with a hyphen rather than a space or another separator.
Why it matters: Typing the hyphen prevents a common command-name error.
Key terms: cmdlet names, verb-noun, dash
4.9.2 Typing parameters
This section explains how to type PowerShell parameters with the required dashes and spaces while recognizing that capitalization usually does not matter.
- Parameter dashes and spacing: Explain how to separate a cmdlet, its parameters, and any parameter values when typing a command, and distinguish these requirements from PowerShell’s usual indifference to capitalization.
Why it matters: Correct spacing and dashes let PowerShell recognize the parameters and values you intended.
Key terms: parameter, parameter name, value, cmdlet, dash
4.10 Lab
4.11 Lab answers
Where this is used later
- PowerShell profiles (chapter 26) · The earlier explanation of PowerShell execution policy.
- (chapter intro) (chapter 19) · The distinction between running commands and writing scripts.
- Not programming, more like batch files (chapter 19) · Assumes familiarity with running commands interactively.
- Making commands repeatable (chapter 19) · Making commands repeatable develops the reuse pattern introduced here.
- (chapter intro) (chapter 6) · The basic form of a command with a cmdlet name and parameters.
- Setting default parameter values (chapter 26) · The distinction between a command and its parameters.
- Finding the commands (chapter 9) · Finding commands can draw on likely names suggested by the naming convention.
- Adding parameter aliases (chapter 20) · PowerShell permits shortened parameter names when they identify the intended parameter.
Concepts explained in this chapter
- PowerShellPowerShell 3 is the third major version of the PowerShell command-line shell.
- commandA command is an executable instruction that a shell can invoke to perform an operation.
- verb-noun naming formatVerb-noun naming is a command and script naming convention that combines an action verb with a descriptive noun.
- -ExecutionPolicy-ExecutionPolicy is a PowerShell startup parameter that specifies an execution policy for the launched session.
- PowerShell execution policyAn execution policy is a machine-wide PowerShell setting that controls whether and under what conditions scripts can run.
- Set-ExecutionPolicySet-ExecutionPolicy is a PowerShell command that changes the execution policy.
- external commandAn external command is an executable program invoked from PowerShell rather than a PowerShell cmdlet or function.
- invocation operatorThe invocation operator is the PowerShell ampersand operator that executes a command whose name or path is supplied as an expression.
- cmdletA cmdlet is a specialized PowerShell command that performs a focused operation and is typically implemented as a .NET class.
- aliasA parameter alias is an alternate name accepted by a command for one of its parameters.
- command-line interfaceA command-line shell is an interactive text-based interface that interprets and runs commands.
- -Syntax-Syntax is a Get-Command parameter that displays the syntax of a command.
- positional parameterA positional parameter is a command or script parameter whose value can be supplied by its position without naming the parameter explicitly.
- PowerShell help systemA help system is an integrated facility that provides software documentation and assistance for discovering and understanding available commands and features.
- Get-CommandGet-Command is a PowerShell cmdlet that retrieves commands matching specified names, verbs, nouns, or command types.
- switch parameterA switch parameter is a Boolean-style command parameter whose presence enables an option without requiring an input value.
- -ErrorAction-ea is a PowerShell parameter alias for -ErrorAction.
- moduleA module is a packaged unit of reusable code and related resources that can be loaded into a software environment.
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.
