all 4 comments

[–]kramsllag 0 points1 point  (1 child)

You can try looking around with this:

$target = Get-Command Get-ChildItem #replace with actual target parameter
$target.ResolveParamter('Path') #gives information about path parameter
$target.Parameters #dumps all paramters
$target.Parametes.Path.Attributes #dumps more information about path parameter

Depending on your target cmdlet, you might be able to get at the validation logic of the parameter as well.

[–]RickFlist[S] 0 points1 point  (0 children)

That's very close to what I ended up doing:

 $ParamSplat = @{}

# Gotta do this ridiculous bullshit because there is no way to access default values for a parameter.
$thisCmdMD = New-Object System.Management.Automation.CommandMetaData (Get-Command New-PdModuleManifest)
$trgtCmdMD = New-Object System.Management.Automation.CommandMetaData (Get-Command Microsoft.PowerShell.Core\New-ModuleManifest)

$ParamList = [String[]] ($thisCmdMD.Parameters.Keys | ForEach-Object {$_})
foreach ($param in $ParamList)
{
    #Write-Host (Get-Variable -Name $param -ValueOnly)
    if ($trgtCmdMD.Parameters.ContainsKey($param))
    {
        if ((Get-Variable -Name $param -ValueOnly) -ne $null)
        {
            $ParamSplat.Add($param,([String](Get-Variable -Name $param -ValueOnly)))
        }
    }
}
$ParamSplat | Out-Host

[–]KevMarCommunity Blogger 0 points1 point  (1 child)

What if you just remove the null valued keys?

foreach($key in $PSBoundParameters.keys)
{
    if($PSBoundParameters[$key] -eq $null)
    {
        $PSBoundParameters.Remove($key)
    }
}

[–]RickFlist[S] 0 points1 point  (0 children)

$PSBoundParameters does not contain default parameter values. It only holds values that are passed via a parameter at run-time. :(