【问题标题】:PowerShell Table column to string delimited with ','PowerShell 表列到以“,”分隔的字符串
【发布时间】:2019-05-23 06:38:19
【问题描述】:

我正在尝试将“键”列下的值转换为以“,”分隔的单个字符串

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

命令返回:

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

我正在努力实现:

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

当我尝试的一切(foreach 循环,.ToString)返回时,我完全迷失了:

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

有什么办法也可以吗?

【问题讨论】:

    标签: string powershell hashtable


    【解决方案1】:
    • 要获取哈希表/字典的键,请使用其.Keys 属性。

    • 要将字符串集合转换为带有分隔符的单个字符串,请使用-join 运算符。

    因此:

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

    【讨论】:

      猜你喜欢
      • 2010-10-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-18
      • 1970-01-01
      • 2016-12-29
      • 2012-08-22
      • 2015-03-29
      相关资源
      最近更新 更多