string - PowerShell 表列到以“,”分隔的字符串
问题描述
我正在尝试将“键”列下的值转换为用“,”分隔的单个字符串
$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],
有没有办法做到这一点?
解决方案
要获取哈希表/字典的键,请使用其
.Keys
属性。要将字符串集合转换为带有分隔符的单个字符串,请使用
-join
运算符。
所以:
$TheTable = (get-command get-mailbox).Parameters.Keys -join ","
推荐阅读
- java - Java中的正则表达式在替代匹配中使用相同的组
- gradle - 有没有办法告诉 gradle 从某个模块构建
- html - Owl carousel 将两张图像显示为一张(4 张图像 - 两个点)
- azure - 如何在不同于默认值的 ARM 模板中为私有端点指定订阅和资源管理器
- laravel - 浏览器打开空白,Laravel Dusk 无法继续使用 Laravel Valet 在 Ubuntu 上进行测试
- r - 使用 cooccur 函数后产生的 NaN
- firebase - 为什么要在电子邮件链接身份验证中通过电子邮件操作处理程序?
- keypress - .keys() 在守夜人中行为不端(即不工作)
- amazon-web-services - AWS Amplify graphQL API:按数组中的值过滤订阅
- javascript - Reactjs - 在模糊事件中隐藏元素