PoshCode Archive  Artifact [a491f9f647]

Artifact a491f9f6476a52cf06ff82e547f5d7bf16b366ae901bab13af95d12e77f1009d:

  • File Get-Parameter.ps1 — part of check-in [73135c4991] at 2018-06-10 13:40:42 on branch trunk — <dl><dt>Description</dt> (user: halr9000 size: 1674)

# encoding: ascii
# api: powershell
# title: Get-Parameter
# description: <dl><dt>Description</dt>
# version: 0.1
# type: function
# author: halr9000
# license: CC0
# function: Get-Parameter
# x-poshcode-id: 442
# x-derived-from-id: 443
# x-archived: 2009-11-13T21:31:30
#
# <dd>Get-Parameter is used to obtain all of the parameters for a cmdlet.  It also returns info like aliases and whether a parameter is mandatory.</dd>
# <dt>Usage:</dt>
# <dd><code>Get-Parameter [Cmdlet Name] | ft -GroupBy ParameterSet</code></dd>
# <dt>Revisions:</dt>
# <dd>0.8
# <ul>
# <li>Does not show common params by default, added switch to override.</li>
# <li>Added Position property</li>
# </ul>
# </dd>
# <dd>0.81
# <ul>
# <li>Added Type column.</li>
# </ul>
# </dd>
# </dl>
#
function Get-Parameter ( $Cmdlet, [switch]$ShowCommon ) {
	foreach ($paramset in (Get-Command $Cmdlet).ParameterSets){
		$Output = @()
		foreach ($param in $paramset.Parameters) {
			if ( !$ShowCommon ) {
				if ($param.aliases -match "vb|db|ea|wa|ev|wv|ov|ob|wi|cf") { continue }
			}
			$process = "" | Select-Object Name, Type, ParameterSet, Aliases, Position, IsMandatory
			$process.Name = $param.Name
			$process.Type = $param.ParameterType.Name 
			if ( $paramset.name -eq "__AllParameterSets" ) { $process.ParameterSet = "Default" }
			else { $process.ParameterSet = $paramset.Name }
			$process.Aliases = $param.aliases
			if ( $param.Position -lt 0 ) { $process.Position = $null }
			else { $process.Position = $param.Position }
			$process.IsMandatory = $param.IsMandatory 
			$output += $process
		}
		Write-Output $Output
		#Write-Host "`n"
	}
}