Skip to content

Instantly share code, notes, and snippets.

@adamdriscoll
Created July 25, 2017 15:01
Show Gist options
  • Save adamdriscoll/5b88d3f85ce222851817eef3be2ae7e8 to your computer and use it in GitHub Desktop.
Save adamdriscoll/5b88d3f85ce222851817eef3be2ae7e8 to your computer and use it in GitHub Desktop.
PSeudoParameterBinding
function Get-BoundParameter {
param($commandAst)
$psuedoParameterBinderType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoParameterBinder')
$bindingTypeType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoParameterBinder+BindingType')
$psuedoParameterBinder = [Activator]::CreateInstance($psuedoParameterBinderType)
$DoPseudoParameterBinding = $psuedoParameterBinderType.GetMethod('DoPseudoParameterBinding', [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic)
$pseudoBindingInfoType = [System.Management.Automation.AliasInfo].Assembly.GetType('System.Management.Automation.Language.PseudoBindingInfo')
$bindingInfo = $DoPseudoParameterBinding.Invoke($psuedoParameterBinder, @($commandAst, $null, $null, $bindingTypeType.GetEnumValues()[0]))
$boundArgumentsProperty = $pseudoBindingInfoType.GetProperty("BoundArguments", [System.Reflection.BindingFlags]::Instance -bor [System.Reflection.BindingFlags]::NonPublic)
$boundArgumentsProperty.GetValue($bindingInfo).GetEnumerator() | % { @{ Name = $_.Key; Ast = $_.Value.Argument } }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment