简体   繁体   中英

PowerShell Table column to string delimited with ','

I am trying to convert values under 'key' column to a single string delimited with ','

$TheTable = (get-command get-mailbox).Parameters 

Command returns:

Key                    Value                                         
---                    -----                                         
ErrorAction            System.Management.Automation.ParameterMetadata
IncludeInactiveMailbox System.Management.Automation.ParameterMetadata
Verbose                System.Management.Automation.ParameterMetadata
OutVariable            System.Management.Automation.ParameterMetadata

I am trying to achieve:

$TheTable = "ErrorAction,IncludeInactiveMailbox,Verbose,OutVariable"

I am completely lost as everything I attempt (foreach loop, .ToString) returns:

System.Collections.Generic.Dictionary`2[System.String,System.Management.Automation.ParameterMetadata],

Is there any way too do that?

  • To get a hashtable's / dictionary's keys, use its .Keys property.

  • To convert a collection of strings to a single string with a separator, use the -join operator.

Therefore:

$TheTable = (get-command get-mailbox).Parameters.Keys -join ","

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