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 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-ProcessThen 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 -ExamplesGet-Help Get-Process -DetailedGet-Help Get-Process -FullHow 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 -DetailedScroll 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 -ExamplesWhen 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 20What to notice:
-LogNameexpects a string (name of the log).-Newestexpects 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 -FullYou’ll typically see syntax lines that include parameters like -Path and -LiteralPath. The difference matters:
-Pathtreats wildcard characters like*as wildcards.-LiteralPathtreats 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\hostsUse 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-MemberLook 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 PropertyThen use those properties:
Get-Process | Sort-Object -Property CPU -Descending | Select-Object -First 53) 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 ServiceGet-Command -Verb Get -Noun ServiceStep 2: Pick a likely cmdlet (for example Get-Service).
Step 3: Read examples first:
Get-Help Get-Service -ExamplesStep 4: Run a safe query with a parameter value:
Get-Service -Name w32timeStep 5: Inspect output to see what properties exist:
Get-Service -Name w32time | Get-MemberPractice 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 EventLogStep 2: Open detailed help and locate the SYNTAX section:
Get-Help Get-EventLog -DetailedStep 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 10Practice 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 ChildItemStep 2: Read examples:
Get-Help Get-ChildItem -ExamplesStep 3: Notice common switches like -Recurse and -Force. Confirm what they do in Detailed help:
Get-Help Get-ChildItem -DetailedStep 4: Run a safe command (read-only) with a switch:
Get-ChildItem -Path C:\Windows -Force | Select-Object -First 20Step 5: Inspect output types:
Get-ChildItem -Path C:\Windows | Get-MemberPractice 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 -FullStep 3: Compare these valid calls:
Get-Process -Name explorerGet-Process -Id 4Step 4: Predict what will happen if you mix sets, then test (expect an error):
Get-Process -Name explorer -Id 4Step 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-Commandto find the cmdlet that lists processes. - Use
Get-Help ... -Examplesto find how to filter by name. - Run a safe command to show only one process by name.
- Pipe the result to
Get-Memberand 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 Serviceto find the cmdlet. - Use
Get-Help -Detailedto 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 Getand search for cmdlets related to content. - Use
Get-Help ... -Fullto compare-Pathvs-LiteralPath. - Run a safe read using
-LiteralPathon 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-, orRestart-). - Use
Get-Help ... -Fullto check whether it supports-WhatIfand-Confirm. - Run it with
-WhatIfso 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 ... -Detailedto confirm the expected type and correct your command.
# Example idea: find a parameter that expects an integer, then try a string, then fix itQuick Reference Table: What to Use and When
| Goal | Command | Tip |
|---|---|---|
| Find cmdlets by name pattern | Get-Command *service* | Use wildcards when you only remember part of the name. |
| Find cmdlets by verb/noun | Get-Command -Verb Get -Noun Service | Great for learning the standard naming scheme. |
| Learn usage quickly | Get-Help Name -Examples | Start here to copy a working pattern. |
| Understand parameters deeply | Get-Help Name -Detailed | Look for Required, Type, Position, Pipeline input. |
| See everything available | Get-Help Name -Full | Use when troubleshooting or learning edge cases. |
| Discover output properties | ... | Get-Member | Use -MemberType Property to focus on data fields. |