Reuse DynamicParam implementations in PowerShell

3. Oktober 2017

Reuse DynamicParam implementations in PowerShell

As I wrote here, there is an easy way to enter into a PowerShell container session, which I enhanced a bit in the second iteration to do dynamic name resolution for the containers.

We now have the „NAV Container Helper“ script which adds some convenience cmdlets when working with container based NAV installs. I wanted to also enhance that with dynamics name resolution without having to add all the code to every cmdlet which turned out to be not that easy. I tried a number of different things and search the Internet but couldn’t find the solution. Then I went to our resident PowerShell guru, Frank-Peter Schultze (follow @fpschultze) and he showed me how to do it:

First you create a helper function which defines the dynamic param. Specific for my usage is only line 20, everything else should be quite generic. If you have additional parameters, you’ll want to look into lines 12-14