Advanced PowerShell functions: CmdletBinding, sets, pipeline
9 steps · about 2 h 41 min · Intermediate
- Functions - PowerShell 101 (tutorial, Microsoft Learn, 25 min)
It starts from simple functions and shows the jump to advanced ones, so you have the basics first.
- about_Functions_Advanced - PowerShell (doc, Microsoft Learn, 10 min)
This is the official overview of what makes a function behave like a cmdlet.
- about_Functions_CmdletBindingAttribute - PowerShell (doc, Microsoft Learn, 20 min)
It covers each CmdletBinding argument, such as DefaultParameterSetName, SupportsShouldProcess and PositionalBinding, plus the common parameters you get for free.
- about_Functions_Advanced_Parameters - PowerShell (doc, Microsoft Learn, 30 min)
Next you learn the Parameter attribute (Mandatory, Position, ValueFromPipeline) and the validation attributes that guard your inputs.
- Advanced PowerShell Functions: Begin to Process to End (blog, SAPIEN Blog, 15 min)
It shows the order in which begin, process and end run when several functions share one pipeline.
- Powershell begin Process End output (article, Microsoft Q&A, 8 min)
It shows the classic mistake of passing an array by parameter versus by pipeline, so you see why you need a foreach inside process.
- about parameter sets (doc, Microsoft Learn, 20 min)
Here you learn the official rules: a parameter with no set belongs to all sets, there is a limit of 32 sets, and the default set is chosen with DefaultParameterSetName.
- PowerShell Tutorial => Simple parameter sets (reference, RIP Tutorial, 8 min)
A compact example you can run to see valid combinations, the 'cannot be resolved' error and mandatory prompts.
- about_Functions_Advanced_Methods - PowerShell (doc, Microsoft Learn, 25 min)
Last, you add $PSCmdlet methods such as ShouldProcess and the Write methods, so your function supports -WhatIf and reports errors properly.