Skip to content

Instantly share code, notes, and snippets.

@techthoughts2
Last active November 15, 2021 15:36
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 techthoughts2/c35e2899ee893e32c9e9aa1aeb895f75 to your computer and use it in GitHub Desktop.
Save techthoughts2/c35e2899ee893e32c9e9aa1aeb895f75 to your computer and use it in GitHub Desktop.
Get all of the parameter values passed into a function
# Get the command name
$CommandName = $PSCmdlet.MyInvocation.InvocationName;
# Get the list of parameters for the command
$ParameterList = (Get-Command -Name $CommandName).Parameters;
# Grab each parameter value, using Get-Variable
foreach ($Parameter in $ParameterList) {
Get-Variable -Name $Parameter.Values.Name -ErrorAction SilentlyContinue;
#Get-Variable -Name $ParameterList;
}
$paramInfo = $MyInvocation.MyCommand.Parameters | Format-Table -AutoSize @{ Label = 'Key'; Expression = { $_.Key }; }, @{ Label = 'Value'; Expression = { (Get-Variable -Name $_.Key -EA SilentlyContinue).Value }; }
Write-Debug ($paramInfo | Out-String)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment