Skip to content

Instantly share code, notes, and snippets.

@congyiwu
Created July 25, 2019 18:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save congyiwu/bcb8200aae90b204ec957d872364e3c4 to your computer and use it in GitHub Desktop.
Save congyiwu/bcb8200aae90b204ec957d872364e3c4 to your computer and use it in GitHub Desktop.
MapCalleeToCallerParams
# Builds an [ordered] containing only params that were explicitly passed in. With splatting, this
# this lets us call another script without overriding its default params.
function MapCalleeToCallerParams {
param(
# An [ordered] where the keys are param names in the script being called (the callee) and
# values are param names in this script (the caller).
[System.Collections.Specialized.OrderedDictionary][Parameter(Mandatory=$true)] $Mappings
)
$result = [ordered]@{}
foreach ($mapping in $Mappings.GetEnumerator()) {
$value = $null
if ($MyInvocation.BoundParameters.TryGetValue($mapping.Value, [ref]$value)) {
$result.Add($mapping.Key, $value);
}
}
return $result
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment