@@ -70,6 +70,10 @@ $Override,
7070[switch ]
7171$Dynamic ,
7272
73+ # If set, will not generate a dynamic parameter block. This is primarily present so Abstract inheritance has a small change footprint.
74+ [switch ]
75+ $NoDynamic ,
76+
7377# If set, will always inherit commands as proxy commands.
7478# This is implied by -Dynamic.
7579[switch ]
@@ -163,6 +167,20 @@ process {
163167 return
164168 }
165169
170+ $InheritTemplate =
171+ if ($resolvedCommand.Inherit ) {
172+ $resolvedCommand.Inherit
173+ } elseif ($resolvedCommand.Module.Inherit ) {
174+ $resolvedCommand.Module.Inherit
175+ }
176+
177+ if ($InheritTemplate -is [Management.Automation.PSMethodInfo ]) {
178+ return $InheritTemplate.Invoke (@ ([Ordered ]@ {} + $PSBoundParameters ))
179+ }
180+ elseif ($InheritTemplate -is [scriptblock ]) {
181+ return (& $InheritTemplate @ ([Ordered ]@ {} + $PSBoundParameters ) )
182+ }
183+
166184 # Prepare parameters for Join-ScriptBlock
167185 $joinSplat = @ {}
168186 foreach ($key in ' IncludeBlockType' , ' ExcludeBlockType' ) {
263281 # If we do not have a resolved command,
264282 if (-not $resolvedCommand ) {
265283 {} # the first script block is empty.
266- } else {
284+ }
285+ else {
267286 # If we have a resolvedCommand, fully qualify it.
268287 $fullyQualifiedCommand =
269288 if ($resolvedCommand.Module ) {
273292 }
274293
275294 # Then create a dynamicParam block that will set `$baseCommand,
276- # as well as a `$script: scoped variable for the command name.
277-
278- [scriptblock ]::create(@"
295+ # as well as a `$script: scoped variable for the command name.
296+ if ($NotDynamic ) # unless, of course -NotDynamic is passed
297+ {
298+ {}
299+ } else
300+ {
301+ [scriptblock ]::create(@"
279302dynamicParam {
280303 `$ baseCommand =
281304 if (-not `$ script:$commandVariable ) {
@@ -302,6 +325,7 @@ dynamicParam {
302325 })
303326}
304327"@ )
328+ }
305329 }
306330),
307331 # Next is our [ScriptBlock]. This will come before almost everything else.
0 commit comments