Tuesday, March 24, 2009

Metadata

Jason Shirk's excellent post on meta-programming inspired this function and alias I have added to my profile to help me get a handle on the use and format of paramaters in CTP2 v3 scripts. 

function Create-Metadata($args0) {
$args0 = new-object System.Management.Automation.CommandMetadata (get-command $args0)
[System.Management.Automation.ProxyCommand]::Create($args0) | out-file ProxyCommand.txt
more ProxyCommand.txt
}
Set-Alias cm Create-Metadata

Run as below:
CM("trace-command")


[CmdletBinding(DefaultParameterSetName='expressionSet')]
param(
    [Parameter(ValueFromPipeline=$true)]
    [System.Management.Automation.PSObject]
    ${InputObject},

    [Parameter(Mandatory=$true, Position=0)]
    [System.String[]]
    ${Name},

    [Parameter(Position=2)]
    [System.Management.Automation.PSTraceSourceOptions]
    ${Option},

    [Parameter(ParameterSetName='expressionSet', Mandatory=$true, Position=1)]
    [System.Management.Automation.ScriptBlock]
    ${Expression},

    [Parameter(ParameterSetName='commandSet', Mandatory=$true, Position=1)]
    [System.String]
    ${Command},

    [Parameter(ParameterSetName='commandSet', ValueFromRemainingArguments=$true)]
    [Alias('Args')]
    [System.Object[]]
    ${ArgumentList},

    [System.Diagnostics.TraceOptions]
    ${ListenerOption},

    [Alias('PSPath')]
    [System.String]
    ${FilePath},

  .....

No comments: