Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powershell C# Cmdlet with Hashtable/Dictionary parameters

Can anyone tell me how to add a parameter to my custom C# cmdlets which is a Hashtable/StringDictionary, so that I can call my cmdlet in a way which resembles this:

 CustomCmdlet -File $someFilePath `
              -StringDictionary/HashtableParameter @{
                            "name1"="value1"
                            "name2"="value2"
                            "name3"="value3"
                            ...
                       }

I simply cannot find any documentation/example which clearly and simple explains how to do this, or if its even possible for custom cmdlets.

Can i just use:

    [Parameter(Mandatory = false, Position = 9)]
    public Dictionary<string,string> FieldValues { get; set; }

    [Parameter(Mandatory = false, Position = 9)]
    public HashTable FieldValues { get; set; }

    ...

Or something else?

Kind regards

like image 413
Christian Mikkelsen Avatar asked Feb 03 '12 22:02

Christian Mikkelsen


1 Answers

You can use the following

public Hashtable[] SearchCriteria { get; set; }

to have the funcitonality like

Start-Process calc -PassThru | Get-UIAWindow | Get-UIAButton -SearchCriteria @{automationid="13*";name="[3-5]"},@{name="c*"},@{name="a*"},@{isenabled="false"} | Read-UIAControlName

The output is

4

Clear entry

5

Clear

3

Add

Maximize

Close

like image 112
Alexander Petrovskiy Avatar answered Oct 17 '22 03:10

Alexander Petrovskiy