PoshCode Archive  Artifact [b5884d310b]

Artifact b5884d310b5618d6fee8e17c311f9d3bfa87b38f4b22f3acfdee482c9970e5f3:

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

# 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: 440
# x-derived-from-id: 441
# x-archived: 2009-11-13T21:31:12
#
# <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>
# </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") { continue }
			}
			$process = "" | Select-Object Name, ParameterSet, Aliases, Position, IsMandatory
			$process.Name = $param.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
	}
}