gpt4 book ai didi

powershell - Export-Csv 等价于 Write-Output

转载 作者:行者123 更新时间:2023-12-02 22:52:11 25 4
gpt4 key购买 nike

如何将对象转换为一系列 CSV 字符串并将字符串输出到另一个命令?

Export-Csv cmdlet 只会输出到一个文件。我想将 CSV 输出发送到另一个命令或脚本输出。

作为解决方法,我可以对文件使用 Export-Csv,读取文件,然后删除文件,但这种方法有太多不必要的开销。

Export-Csv

Converts objects into a series of comma-separated value (CSV) strings and saves the strings to a file.

最佳答案

你应该使用 ConvertTo-CSV cmdlet,如果您想将对象转换为 CSV 并将结果返回到标准输出,而不是文件。

The ConvertTo-CSV cmdlet returns a series of comma-separated value (CSV) strings that represent the objects that you submit. You can then use the ConvertFrom-Csv cmdlet to recreate objects from the CSV strings. The objects converted from CSV are string values of the original objects that contain property values and no methods.

您会发现大多数内置 Export- cmdlet 都有一个 ConvertTo- 等效项。另一种发现 cmdlet 的好方法是使用带有通配符的 Get-Command:

~> Get-Command *csv

CommandType Name Version Source
----------- ---- ------- ------
Alias epcsv -> Export-Csv
Alias ipcsv -> Import-Csv
Cmdlet ConvertFrom-Csv 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet ConvertTo-Csv 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Export-Csv 3.1.0.0 Microsoft.PowerShell.Utility
Cmdlet Import-Csv 3.1.0.0 Microsoft.PowerShell.Utility

关于powershell - Export-Csv 等价于 Write-Output,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55921369/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com