I was working on a tricky problem with Pester’s mocking functionality today, and came across something that I didn’t previously know about how dynamic parameters work in PowerShell. Dynamic parameters are generated before (and only before) pipeline input is processed.
This means that if your dynamicparam block depends on the values of a parameter that happens to accept pipeline input, you won’t get your dynamic parameters when a user chooses to use that pipeline input functionality.
This is true of both compiled Cmdlets, and Advanced Functions. For example:
# This works fine: Get-ChildItem -Path 'Cert:\' -CodeSigningCert -Recurse # And this generates an error that the CodeSigningCert # parameter cannot be found: 'Cert:\CurrentUser' | Get-ChildItem -CodeSigningCert -Recurse