在 Powershell 中控制转录期间的换行符 - 也许是记事本

Controlling Line Breaks During Transcript in Powershell -maybe notepad

当用记事本打开时,以下代码会在我的文本文件 egg.txt 中生成以下一行条目 - 但是记事本++可以识别换行符:

脚本:

Start-Transcript egg.txt
Get-ChildItem -file | Copy-Item -Destination "c:\egg" -Verbose
Stop-Transcript

输出 - 记事本:

VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\Craig\.gitconfig Destination: C:\egg".VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\Craig\.zip Destination: C:\egg".VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\Craig\egg.txt Destination: C:\egg".

输出-记事本++:

VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\Craig\.gitconfig Destination: C:\egg".
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\Craig\.zip Destination: C:\egg".
VERBOSE: Performing the operation "Copy File" on target "Item: C:\Users\Craig\egg.txt Destination: C:\egg".

我想我可以按照

的方式做点什么
  get-content | "string manipulate `n,`r`n" | set-content 

在脚本末尾(这可能会给我太多行)或者只是用记事本以外的东西打开文件?

我可以设置 start-transcript 上的一些设置吗?

Start-Transcript cmdlet 并不真正被视为一种 日志记录 机制,而更像是对所执行命令的简单捕获,您可以从中 copy/paste播放脚本的片段。

您可以像这样为记事本生成一个带有适当 CR/LF 的日志文件。

Start-Transcript egg.txt
Get-ChildItem -file | Copy-Item -Destination "c:\egg" -Verbose
Stop-Transcript

$log = Get-Content egg.txt
$log > Log.txt

不是很优雅,但很管用。

我知道这已经过时了,但对于像我一样遇到过此问题的人,请尝试将抄本发送到 .log 文件。 .log 尊重这些换行符。我建议下载 trace32.exe 来查看这些日志,您会喜欢它的外观 - 我保证。