C # Powershell Cmdlet with Hashtable / Dictionary Parameters

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

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

I just can't find any documentation / example that clearly and simply explains how to do this, or, if possible, even 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?

Yours faithfully

+4
source share
1 answer

You can use the following

 public Hashtable[] SearchCriteria { get; set; } 

to have funcitonality like

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

Output signal

4

Delete entry

5

Clear

3

Add

Maximization

Close

+4
source

Source: https://habr.com/ru/post/1394705/


All Articles