Advanced PowerShell functions: CmdletBinding, sets, pipeline

9 steps · about 2 h 41 min · Intermediate

  1. 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.

  2. about_Functions_Advanced - PowerShell (doc, Microsoft Learn, 10 min)

    This is the official overview of what makes a function behave like a cmdlet.

  3. 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.

  4. 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.

  5. 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.

  6. 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.

  7. 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.

  8. 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.

  9. 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.