Last active
November 15, 2021 15:36
-
-
Save techthoughts2/c35e2899ee893e32c9e9aa1aeb895f75 to your computer and use it in GitHub Desktop.
Get all of the parameter values passed into a function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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