Free Ebook cover Windows PowerShell for Beginners: Everyday Automation and System Insights

Windows PowerShell for Beginners: Everyday Automation and System Insights

New course

10 pages

Understanding Cmdlets, Parameters, and PowerShell Help

Capítulo 2

Estimated reading time: 9 minutes

+ Exercise

Cmdlets, Parameters, and Parameter Sets: The Core Idea

A cmdlet is a small command that performs one focused action (for example, getting processes, listing services, or reading a file). Cmdlets become flexible through parameters, which are named inputs that change what the cmdlet does. Parameters can accept values (like a name, path, or number) or act as switches (on/off flags).

Many cmdlets support multiple ways to run them. Each supported “shape” of usage is a parameter set. A parameter set is a valid combination of parameters. If you mix parameters from different sets, PowerShell will stop and tell you the parameters cannot be used together.

Concrete example: one cmdlet, multiple parameter sets

Get-Process can be used in different ways:

  • By name: Get-Process -Name powershell
  • By ID: Get-Process -Id 1234

Those are different parameter sets. You can’t combine them like Get-Process -Name powershell -Id 1234 because that would be ambiguous.

Routine Workflow: Find It, Read It, Inspect Output

A practical self-service workflow for learning any cmdlet is:

Continue in our app.

You can listen to the audiobook with the screen off, receive a free certificate for this course, and also have access to 5,000 other free online courses.

Or continue reading below...
Download App

Download the app

  • Find the cmdlet: Get-Command
  • Read how to use it: Get-Help (especially syntax and examples)
  • Inspect what it outputs: pipe to Get-Member

This workflow helps you answer three questions quickly: “What command do I need?”, “How do I call it correctly?”, and “What properties/methods can I use next?”

1) Reading Syntax from Help

Get help for a cmdlet

Start with the cmdlet name:

Get-Help Get-Process

Then use the help views depending on what you need:

  • -Detailed: adds parameter descriptions and more context
  • -Full: everything (including notes, inputs/outputs, and more)
  • -Examples: just the examples (often the fastest way to learn)
Get-Help Get-Process -Examples
Get-Help Get-Process -Detailed
Get-Help Get-Process -Full

How to read the SYNTAX section

In help, syntax is shown like this (format varies by cmdlet):

Get-Process [[-Name] <String[]>] [-ComputerName <String[]>] [-Module] [-FileVersionInfo] [<CommonParameters>]

Key things to recognize:

  • Square brackets [ ] mean “optional”. If it’s not in brackets, it’s required in that parameter set.
  • Angle brackets < > show the expected type, like <String>, <Int32>, <DateTime>, or arrays like <String[]>.
  • Multiple syntax lines usually mean multiple parameter sets.
  • Switch parameters appear without a value type (or are shown as [-SwitchName]). You pass them by including them: -Module, not -Module $true.
  • Positional parameters: if you see something like [[-Name] <String[]>], it often means you can supply the value without typing -Name (position 0). Example: Get-Process powershell.

Recognizing mandatory parameters

Mandatory parameters are easiest to spot in two places:

  • In SYNTAX: parameters not in brackets are required for that parameter set.
  • In PARAMETERS (Detailed/Full): look for Required? true (or similar wording).

Example: inspect parameter details:

Get-Help Get-Service -Detailed

Scroll to the PARAMETERS section and look for:

  • Required: whether PowerShell will prompt you if missing
  • Position: whether you can omit the parameter name
  • Default value: what happens if you don’t specify it
  • Accept pipeline input: whether it can take objects from the pipeline

Accepted value types and validation

Help shows the type (for example <String>), but some parameters also restrict values. Common patterns:

  • Enumerated values (ValidateSet): only specific strings are allowed (help often lists them).
  • Numeric ranges (ValidateRange): only values within a range are accepted.
  • Patterns (ValidatePattern): values must match a regex pattern.

When you pass the wrong type or an invalid value, PowerShell throws a parameter binding/validation error. Your first troubleshooting step should be: re-check the parameter’s type and allowed values in help.

Common switches you’ll see often

Switch parameters are common because they are easy to use and safe to test:

  • -WhatIf: shows what would happen without making changes (supported by many “change” cmdlets)
  • -Confirm: asks for confirmation before acting
  • -Force: overrides some prompts/restrictions (use carefully)
  • -Verbose: prints extra detail about what the cmdlet is doing

Not every cmdlet supports all switches. Check help to confirm.

2) Exploring Examples (Fast Learning Mode)

Examples are often the quickest path from “I found a cmdlet” to “I can use it correctly.” Use:

Get-Help Get-EventLog -Examples

When reading examples, look for:

  • Which parameters are used together (reveals parameter sets)
  • Whether values are quoted (strings with spaces need quotes)
  • Whether the example uses pipeline input
  • Whether it uses formatting cmdlets (which affects display, not the underlying objects)

Example walkthrough: filtering with parameter values

Suppose you want recent entries from a Windows event log. A typical example might use:

Get-EventLog -LogName System -Newest 20

What to notice:

  • -LogName expects a string (name of the log).
  • -Newest expects a number (how many entries).
  • This is a safe read-only command: it doesn’t change system state.

Example walkthrough: parameter sets in action

Get-Content is commonly used to read files. It can accept a path in different ways. Compare:

Get-Help Get-Content -Full

You’ll typically see syntax lines that include parameters like -Path and -LiteralPath. The difference matters:

  • -Path treats wildcard characters like * as wildcards.
  • -LiteralPath treats the path exactly as typed (useful if the filename contains [ ] or other wildcard characters).

Try safe reads:

Get-Content -Path C:\Windows\System32\drivers\etc\hosts

Use Get-Member to understand what you got back

Help tells you how to call a cmdlet; Get-Member tells you what it returns. This is essential for chaining commands.

Get-Process | Get-Member

Look for:

  • TypeName at the top (the .NET type)
  • Properties (data you can read, filter, sort)
  • Methods (actions you can call, less common for beginners)

Example: discover useful properties for processes:

Get-Process | Get-Member -MemberType Property

Then use those properties:

Get-Process | Sort-Object -Property CPU -Descending | Select-Object -First 5

3) Practicing Parameter Usage (Step-by-Step)

Practice A: Find the right cmdlet for a task (Get-Command)

Task: “I want a command to list services.”

Step 1: Search by noun and verb patterns:

Get-Command -Noun Service
Get-Command -Verb Get -Noun Service

Step 2: Pick a likely cmdlet (for example Get-Service).

Step 3: Read examples first:

Get-Help Get-Service -Examples

Step 4: Run a safe query with a parameter value:

Get-Service -Name w32time

Step 5: Inspect output to see what properties exist:

Get-Service -Name w32time | Get-Member

Practice B: Identify mandatory parameters and valid combinations

Task: “I want to query a specific Windows event log.”

Step 1: Find candidate cmdlets:

Get-Command -Verb Get -Noun EventLog

Step 2: Open detailed help and locate the SYNTAX section:

Get-Help Get-EventLog -Detailed

Step 3: Identify what you must provide. For many systems, -LogName is required for meaningful output. Confirm in the PARAMETERS section.

Step 4: Run a safe command:

Get-EventLog -LogName Application -Newest 10

Practice C: Learn parameter types by intentionally checking help

Task: “I want to list files in a folder and include hidden items.”

Step 1: Find the cmdlet:

Get-Command -Verb Get -Noun ChildItem

Step 2: Read examples:

Get-Help Get-ChildItem -Examples

Step 3: Notice common switches like -Recurse and -Force. Confirm what they do in Detailed help:

Get-Help Get-ChildItem -Detailed

Step 4: Run a safe command (read-only) with a switch:

Get-ChildItem -Path C:\Windows -Force | Select-Object -First 20

Step 5: Inspect output types:

Get-ChildItem -Path C:\Windows | Get-Member

Practice D: Parameter sets and “cannot be used together” errors

Task: Understand why some parameter combinations fail.

Step 1: Choose a cmdlet with multiple parameter sets, such as Get-Process.

Step 2: View full help and look for multiple SYNTAX lines:

Get-Help Get-Process -Full

Step 3: Compare these valid calls:

Get-Process -Name explorer
Get-Process -Id 4

Step 4: Predict what will happen if you mix sets, then test (expect an error):

Get-Process -Name explorer -Id 4

Step 5: Use the error message as a clue, then return to the SYNTAX section to see which parameters belong together.

Exercises (Self-Service Learning Drills)

Exercise 1: Find a cmdlet to show running processes, then learn its output

  • Use Get-Command to find the cmdlet that lists processes.
  • Use Get-Help ... -Examples to find how to filter by name.
  • Run a safe command to show only one process by name.
  • Pipe the result to Get-Member and identify at least three useful properties (for example, Id, CPU, WorkingSet).
# Your work area (fill in the blanks with real commands you discovered via Get-Command/Get-Help)

Exercise 2: Find a cmdlet to list services and filter by status

  • Use Get-Command -Noun Service to find the cmdlet.
  • Use Get-Help -Detailed to find which parameter accepts the service name and whether it’s positional.
  • Run a safe command that lists only running services (hint: you may filter using properties you discover with Get-Member).
# Example pattern (adapt based on what Get-Member shows you)

Exercise 3: Find a cmdlet to read a text file and handle special characters in paths

  • Use Get-Command -Verb Get and search for cmdlets related to content.
  • Use Get-Help ... -Full to compare -Path vs -LiteralPath.
  • Run a safe read using -LiteralPath on a file path that includes characters like [ or ] (create a test file if needed).
# Example (adjust the path to a file you create for practice)

Exercise 4: Use help to choose safe parameters for a “change” cmdlet

  • Pick a cmdlet that changes something (for example, a cmdlet with Set-, New-, Remove-, or Restart-).
  • Use Get-Help ... -Full to check whether it supports -WhatIf and -Confirm.
  • Run it with -WhatIf so it performs no changes, and read the output carefully.
# Template (replace with your chosen cmdlet if it supports -WhatIf)

Exercise 5: Diagnose a parameter binding problem using help

  • Choose a cmdlet and intentionally pass a value of the wrong type (for example, pass text where a number is expected).
  • Read the error message.
  • Use Get-Help ... -Detailed to confirm the expected type and correct your command.
# Example idea: find a parameter that expects an integer, then try a string, then fix it

Quick Reference Table: What to Use and When

GoalCommandTip
Find cmdlets by name patternGet-Command *service*Use wildcards when you only remember part of the name.
Find cmdlets by verb/nounGet-Command -Verb Get -Noun ServiceGreat for learning the standard naming scheme.
Learn usage quicklyGet-Help Name -ExamplesStart here to copy a working pattern.
Understand parameters deeplyGet-Help Name -DetailedLook for Required, Type, Position, Pipeline input.
See everything availableGet-Help Name -FullUse when troubleshooting or learning edge cases.
Discover output properties... | Get-MemberUse -MemberType Property to focus on data fields.

Now answer the exercise about the content:

You run Get-Process -Name explorer -Id 4 and PowerShell reports that the parameters cannot be used together. What is the best explanation?

You are right! Congratulations, now go to the next page

You missed! Try again.

Many cmdlets have multiple parameter sets (valid combinations). For Get-Process, using -Name is one set and using -Id is another. Combining parameters from different sets causes a “cannot be used together” error.

Next chapter

PowerShell Pipelines: Passing Objects Instead of Text

Arrow Right Icon
Download the app to earn free Certification and listen to the courses in the background, even with the screen off.