powershell - 如何在 Powershell 中加入两个对象数组
问题描述
我的 powershell 脚本中有两个对象数组
第一个有这样的价值观
@{Id=1, Count=24}
@{Id=2, Count=34}
第二
@{Id=1, Name="Some name"}
@{Id=2, Name="Some other name"}
我喜欢加入这两个所以我得到
@{Id=1, Count=24 Name="Some name"}
etc
最终我需要将它写入一个 csv 文件。
解决方案
使用此Join-Object
cmdlet(另请参阅:在 Powershell 中,将两个表合并为一个的最佳方法是什么?)其中(自定义)对象(包括数据表)和哈希表:
$Array1 = @{Id=1; Count=24},
@{Id=2; Count=34}
$Array2 = @{Id=1; Name="Some name"},
@{Id=2; Name="Some other name"}
$Array1 | Join $Array2 -On Id
Count Id Name
----- -- ----
24 1 Some name
34 2 Some other name
推荐阅读
- angular - Angular Concat 多个 HTTP 请求
- amazon-web-services - AWS API IoT 的终端节点是什么?
- sql - 如何跨多个数据库查询
- python - 为什么没有选择正确的值?
- java - 如何将此字符串分隔 2 个字符增量?
- python - Asyncio - 等到一行代码执行
- twilio - 如何将 RequestValidator 与 API 密钥一起使用?
- c - 用c中的堆栈检查字符串中的平衡括号
- java - IntStream 和 Stream 有什么区别
? - python - pipenv install pytorch cpu + 具体版本