Tinkering with V3 ISE – an add-on for splatters

Update: I did a re-work of the script, and added some screenshots, here.

Tinkering with the new V3 ISE some more.

This is a rough “proof of concept” for an add-on that writes a hash table snippet for splatting parameters to a cmdlet.

The add-on prompts for a cmdlet name you want to splat parameters for, and a variable name to assign to the hash table to use for splatting.

It verifies the cmdlet name entered is a valid command with “Cmdlet” capability, and then uses the OutputMode features of Out-Gridview to present you with a list of the parameter sets for the cmdlet, using Single output mode so that you can select one paramtertset to use.

Then it presents you with the parmeters for that parmeterset using Out-Gridview using the Multiple output mode so that you can select the paremeters you want to splat.

After your selections are made, a snippet is written to the script pane at the current cursor location to create a hash table of parameters you want to splat, and the cmdlet with that hash table splatted.

function Make-ParamHash {
$cmdlet = read-host "Enter cmdlet for parameter hash"
if ((get-command $cmdlet).capability -match "Cmdlet"){
    $varname = read-host "Enter variable name for hash"
        if ($varname.trim('$') -match '\w+'){    

$param_hash = @("`$$varname = `@`{")
(get-command $cmdlet).parametersets |
 ogv -OutputMode Single -Title "Select Propert Set" |
    %{$_.parameters | ogv -OutputMode Multiple -Title "Select Properties for hash"} |
        %{$param_hash += "`t$($_.name) = "}
    $param_hash += "`t`}"
    $param_hash += "`n $cmdlet `@$varname"
    $param_hash = $param_hash -join "`n"
    $ise_current_file = $psise.CurrentFile

$psISE.CurrentPowerShellTab.AddOnsMenu.Submenus.Add("Param Hash",{Make-ParamHash},"Ctrl+Shift+M")

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s