简体   繁体   English

PowerShell 表列到以“,”分隔的字符串

[英]PowerShell Table column to string delimited with ','

I am trying to convert values under 'key' column to a single string delimited with ','我正在尝试将“key”列下的值转换为以“,”分隔的单个字符串

$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:当我尝试的一切(foreach 循环,.ToString)返回时,我完全迷失了:

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.要获取哈希表/字典的键,请使用其.Keys属性。

  • To convert a collection of strings to a single string with a separator, use the -join operator.要将字符串集合转换为带有分隔符的单个字符串,请使用-join运算符。

Therefore:所以:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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