I think you are looking for automated variable $PSBoundParameters
which is captures input parameters and their values etc.
While I am still not 100% sure what exactly you are looking for I will try to suggest you a couple of advices.
Here's a code samples I just made:
By this one I hope you would get the point of how $PSBoundParameters works.
function Do-This
{
param(
[String[]]$Employees,
[String[]]$Departments,
[String[]]$Courses
)
$Keys = $PSBoundParameters.Keys
foreach ($Key in $Keys)
{
New-Object PSObject -Property @{
Name=$Key
Type=$PSBoundParameters[$Key].GetType()
}
}
}
Do-This -Employees @('EmployeeA','EmployeeA','EmployeeC') -Departments @('Communication','Mathematics','ComputerScience') -Courses @('CourseA','CourseB','CourseC')
There is also a great way to get function information such as parameter names and their types - Get-Help
cmdlet. Here is a function i've made based on it's output.
function Get-FunctionParams
{
param([Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,Position=0)][string]$FunctionName)
$Results = @()
$Parameters = @((Get-Help $FunctionName).parameters.parameter)
if ($Parameters.Count -eq 0)
{
Write-Host $('Function {0} has no parameters' -f $FunctionName)
break
}
foreach ($Parameter in $Parameters){
$Object = New-Object -TypeName PSObject
$Object | Add-Member -MemberType NoteProperty -Name Name -Value $Parameter.name
$Object | Add-Member -MemberType NoteProperty -Name aliases -Value $Parameter.aliases
$Object | Add-Member -MemberType NoteProperty -Name required -Value $Parameter.required
$Object | Add-Member -MemberType NoteProperty -Name type -Value $Parameter.type.name
$Object | Add-Member -MemberType NoteProperty -Name position -Value $Parameter.position
$Object | Add-Member -MemberType NoteProperty -Name defaultValue -Value $Parameter.defaultValue
$Object | Add-Member -MemberType NoteProperty -Name parameterSetName -Value $Parameter.parameterSetName
$Results += $Object
}
Write-Output $Results | Sort-Object position,Name | Format-Table -AutoSize -Wrap
}
Usage example Get-FunctionParams -FunctionName Get-Process
Output of usage example:
Name aliases required type position defaultValue parameterSetName
---- ------- -------- ---- -------- ------------ ----------------
Name ProcessName false string[] 0 Name
ComputerName Cn false string[] Имя задано (Все)
FileVersionInfo FV, FVI false switch Имя задано (Все)
Id PID true int[] Имя задано Id
InputObject Отсутствует true Process[] Имя задано InputObject
Module Отсутствует false switch Имя задано (Все)