PowerShell Medium · Lesson 1 · On the house

Advanced functions and CmdletBinding

Make functions behave like cmdlets. Lesson 1 is free — on the house.

Lessons · PowerShell Medium · Lesson 1 of 10 · On the house

Advanced functions and CmdletBinding

Make functions behave like cmdlets.

Illustration for PowerShell
Lesson 1 is on the house.

[CmdletBinding()] turns a function into an advanced function with common parameters.

You gain -Verbose, -ErrorAction, -PipelineVariable, and SupportsShouldProcess for -WhatIf.

param() with ValueFromPipeline / ValueFromPipelineByPropertyName enables real pipeline binding.

process { } runs per pipeline object; begin/end wrap setup and teardown.

Write-Verbose messages appear only when callers pass -Verbose.

cmdletbinding

function Get-NameUpper { [CmdletBinding()] param([Parameter(ValueFromPipeline)][string]$Name) process { $Name.ToUpper() } }
Match this when you type.

Quiz

What does [CmdletBinding()] enable?

Quiz

Which block runs once per pipeline object?

Quiz

SupportsShouldProcess adds?

Quiz

ValueFromPipeline allows?

Check

Match the still for: Advanced functions and CmdletBinding.

Open-book: the answers are on this page. Pass every quiz and check (5) to mark the lesson done. This visit: 0/5.