微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

get-parameter.ps1

http://halr9000.com/article/507
 
param ( 
  $Cmdlet,[switch]$ShowCommon,[switch]$Full
)

$command = Get-Command $Cmdlet -ea silentlycontinue 

# resolve aliases (an alias can point to another alias)
while ($command.CommandType -eq "Alias") {
	$command = Get-Command ($command.deFinition)
}
if (-not $command) { return }

foreach ($paramset in $command.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,Pipeline,PipelineByPropertyName
		$process.Name = $param.Name
		if ( $param.ParameterType.Name -eq "SwitchParameter" ) {
			$process.Type = "Boolean"
		}
		else {
			switch -regex ( $param.ParameterType ) {
				"Nullable``1\[(.+)\]" { $process.Type = $matches[1].Split('.')[-1] + " (nullable)" ; break }
				default { $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
		$process.Pipeline = $param.ValueFromPipeline
		$process.PipelineByPropertyName = $param.ValueFromPipelineByPropertyName
		$output += $process
	}
	if ( ! $Full ) { 
		$Output | Select-Object Name,Pipeline
	}
	else { Write-Output $Output }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐