Functions/Scripting/Parametrics/Add-DynamicParameterVariables.ps1

<#
.Synopsis
   This function creates parent-scoped variables for each of the dynamic parameters that are defined in a scripts RuntimeParameterDictionary.
.DESCRIPTION
   The normal mechanism of passing defined dynamic parameter values into the $PSBoundParameters dictionary during runtime is not optimal.
   It does not allow the passing forward of any default values for non-mandatory dynamic parameters even though they can be defined
   in the RunTimeParameterDictionary object. So this function which should be run in the Begin {} scriptblock will make sure that all dynamic parameters
   have a variable created for them in the parent function/script just like the static parameters do already.
    
   Additionally, if there are any default values on non-mandatory dynamic parameters that have been defined in the Dynamic Parameter Dictionary
   but were not explicitly set during the execution the script, they will also have parent scope variables created for them in order for those default values to be
   available to the rest of the script. This is a cool feature!
 
   It takes in DynamicDictionary ($RuntimeParameterDictionary from the DynamicParam Block in most scripts)
.EXAMPLE
   Add-DynamicParameterVariables -DynamicDictionary $RuntimeParameterDictionary
#>

function Add-DynamicParameterVariables
{
    [CmdletBinding()]
    Param
    (
        [Parameter(Mandatory=$true)]
        [System.Management.Automation.RuntimeDefinedParameterDictionary]
        $DynamicDictionary
    )

    Process
    {
        # Create Variables from Dynamic Dictionary Keys
        foreach ($key in $DynamicDictionary.Keys) {if ($dynamicdictionary.$key.IsSet){$V = New-Variable -Name $key -Value $DynamicDictionary.$key.value -Scope 1 -Force}}          
    }
}