powershell-3.0 - 如何在管道后使用 "-join"命令

标签 powershell-3.0

我正在使用 powershell 3.0 进行培训,我正在尝试以字节为单位获取文件的内容,通过管道将其发送以加入结果,因为默认情况下每行一个字节,然后将结果发送到文件中.

这是我正在使用的命令:

get-content 'My file' -Encoding byte | $_ -join ' ' | Out-File -path 'My result file'

总而言之,有人知道如何使用 -join在管道之后?

最佳答案

你不能做 -join通过管道,因为管道阶段一次只能看到一个对象。

相反,处理由 get-content 返回的集合。作为单个对象并加入它。

(get-content -path 'my file' -Encoding Byte) -join ' ' | out-file -path 'My result file';

关于powershell-3.0 - 如何在管道后使用 "-join"命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24431848/

相关文章:

c# - 如何使用与其他 DLR 语言类似的 API 在 c# 应用程序中托管 PowerShell 3.0

Powershell:粘贴最后一个命令

powershell - 代码似乎需要Powershell 4,但是看不到为什么

powershell - csv文件的ForEach-Object调用属性从没有空格变为有空格

c# - 如何将参数作为类而不是字符串传递给 New-Object?

PowerShell cmdlet 参数值选项卡完成

Azure (PowerShell) 如何向多个现有网络安全组添加额外的 IP(源地址前缀字段)?

Azure 自动化调用-Sqlcmd : Login failed for user '<token-identified principal>'

powershell-3.0 - 计算 PowerShell 中空行之前的行 #

powershell - 如何从文件夹中的所有文本文件中删除单词?