Functions/Scripting/Parametrics/Get-DefaultParamValues.ps1
Function Get-DefaultParamValues { [cmdletbinding()] Param ( # Name of Command to Query [Parameter(Mandatory=$true)] [String] $CommandName ) Process { # Instantiate new Parameter Hash $defaultParams = [ordered]@{} # Get AST Element for Command $AST = (Get-Command $CommandName).ScriptBlock.Ast # Parse AST Data into Parameter Hash $ASTData = @($ast.FindAll({ $args[0] -is [System.Management.Automation.Language.ParameterAst] }, $true) | where { $_.DefaultValue }) Foreach ($A in $ASTData) { $Type = $A.StaticType.Name $Value = Switch ($Type) { "String" {[string]$A.DefaultValue.Value} "Boolean" {IF($A.DefaultValue.VariablePath.UserPath -eq "True"){$TRUE}else{$False}} Default {$A.DefaultValue.Extent.Text -replace "`"|'"} } $defaultParams[$A.Name.VariablePath.UserPath] = $Value } # Output Parameter Hash $defaultParams } } |