简体   繁体   中英

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM