通过powershell向多个文件添加文本

通过powershell向多个文件添加文本,powershell,text,coding-style,Powershell,Text,Coding Style,我正在尝试定制这里描述的代码 对我来说。我有多个仅带有数字的csv文件,在第一行,我希望有一个特定的短语(例如,文件)。 我正在做以下工作: > 你有没有想过我会错在哪里? 非常感谢 谢谢大家的帮助。我终于想出了一个有效的办法: $header=@" catchment rainfall "@ Get-ChildItem .\testing\ -Recurse -Filter *.csv| Foreach-Object { $header+"`n"+ (Get-Content $_.FullN

我正在尝试定制这里描述的代码 对我来说。我有多个仅带有数字的csv文件,在第一行,我希望有一个特定的短语(例如,文件)。 我正在做以下工作: >

你有没有想过我会错在哪里?
非常感谢

谢谢大家的帮助。我终于想出了一个有效的办法:

$header=@"
catchment rainfall
"@ 
Get-ChildItem .\testing\ -Recurse -Filter *.csv| Foreach-Object { $header+"`n"+ (Get-Content $_.FullName | Out-String) | Set-Content -Path $_.FullName}

谢谢大家的帮助。我终于想出了一个有效的办法:

$header=@"
catchment rainfall
"@ 
Get-ChildItem .\testing\ -Recurse -Filter *.csv| Foreach-Object { $header+"`n"+ (Get-Content $_.FullName | Out-String) | Set-Content -Path $_.FullName}

错误是什么?顺便说一句,验证代码:在第2行的开头,您有一个
。您的代码在其他地方似乎正常…当您删除
| Set Content
?哼哼..在foreach对象中,
似乎有问题,错误是:意外的标记“
n”+(获取内容$.FullName | Out字符串)|在表达式或语句中设置内容-P ath$97;.FullName“”。在第2行char:86+$header
n“+(获取内容$uu.FullName |输出字符串)|设置内容-路径$F.ullName”我还想在第一篇文章中提到,其中*.aspx,我实际上有*.csv,但我认为这不是问题。尝试了这个方法,但仍然无效:(:$header=@“集水区降雨”@Get-ChildItem D:\Documents and Settings\mary\testing\mary00-Recurse-Filter*.csv |>Foreach对象{$header`n+(Get-Content$\.FullName | Out String)| Set-Content-Path$\.FullName}有什么错误?顺便验证代码:在第2行的开头有一个
。您的代码在其他地方似乎正常…当您删除
| Set Content
时,输出是什么?哼哼..在foreach对象中,
似乎有问题”
错误是:意外标记“
n”+(获取内容$.FullName | Out字符串)|设置内容-P ath$.FullName“'in expression or statement.At line:2 char:86+$header
n”+(Get Content$..FullName | Out String)| Set Content-Path$.\uf.ullName”我还想在第一篇文章中提到,*.aspx,我实际上有*.csv,但我认为这不是问题。尝试了这个方法,但仍然无效:(:$header=@“集水区降雨”@Get-ChildItem D:\Documents and Settings\mary\testing\mary00-Recurse-Filter*.csv |>Foreach对象{$header`n+(Get-Content$\uU2.FullName | Out String)| Set-Content-Path$\uU3.FullName}