> test.txt PS C:\code> "test2" >> test.txt -6ren">
gpt4 book ai didi

powershell - Powershell:将object []输出到文件

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

我想检索文件的内容,进行过滤和修改,然后将结果写回到文件中。我这样做:

PS C:\code> "test1" >> test.txt
PS C:\code> "test2" >> test.txt
PS C:\code> $testContents = Get-Content test.txt
PS C:\code> $newTestContents = $testContents | Select-Object {"abc -" + $_}
PS C:\code> $newTestContents >> output.txt

output.txt包含
"abc -" + $_                                                                                                           
------------
abc -test1
abc -test2

第一行带来了什么?几乎就像foreach返回IEnumerable一样-但是$ newTestContents.GetType()表明它是一个对象数组。那有什么呢?我如何才能在没有奇怪的 header 的情况下正常输出数组。

如果您能告诉我$ newTestContents [0] .ToString()为什么是空白字符串,还可以加分

最佳答案

使用ForEach代替Select-Object

关于powershell - Powershell:将object []输出到文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1633127/

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