liveBook · Manning

Cmdlet

As explained in Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools

A cmdlet is a specialized PowerShell command implemented as a .NET class for performing a focused operation.

A cmdlet is a specialized PowerShell command implemented as a .NET class for performing one focused operation. Cmdlets provide an administrator-friendly interface to capabilities exposed by .NET Framework, CIM, COM, and Windows APIs, using consistent names and parameters. section 25.1

Treat a cmdlet like a focused tool rather than a miniature application. Combine small cmdlets in a pipeline or controller script to complete larger processes, instead of building one command that handles unrelated tasks. section 3.1 section 6.1

Use cmdlets effectively by following these practical rules:

  • Give each tool one task and make it behave like a built-in PowerShell command. section 3.1
  • Connect focused tools with pipelines or controller scripts when the operation is really a larger process. section 3.1 section 6.1
  • Prefer cmdlet wrappers over embedding arbitrary raw .NET or C# code in scripts. section 25.1

Focused commands in a pipeline

Get-Process retrieves processes, while Stop-Process stops them; neither becomes a broad “Manage-Processes” command. A disk-reporting pipeline can retrieve logical disks, filter local drives, and select the required properties. section 6.1

Figure 3.1 The single, most important rule you need to remember

Use the single-task rule as a quick design check before combining commands into a larger automation process. section 3.1

How Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools covers it

How deep it goes
Explains cmdlets as .NET-backed wrappers and emphasizes single-task design, but does not detail class implementation steps.
Examples
Uses Get-Process, Stop-Process, logical-disk reporting, and decomposed user provisioning as concrete examples.
What you can do after
Apply cmdlets as focused, composable tools and separate individual tasks from controller-level processes.
How it connects
Connects cmdlets with .NET Framework, C#, CIM, COM, Windows APIs, pipelines, functions, and controller scripts.

Also explained in

Compare how 2 books explain cmdlet →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Learn PowerShell Scripting in a Month of Lunches, Second Edition: Write and organize scripts and tools. The section links point to the parts of the book it draws on.