Powershell 命令在每个文件之前添加文本

标签 powershell powershell-2.0 azure-powershell

我正在尝试构建一个 PowerShell 命令来从多个文件夹中提取所有文件并将其合并到一个文件中。

脚本:

Get-ChildItem -Path $(Pipeline.Workspace)/Common_All/Drop_$(DropFolder)_Migrations -Filter "Release*" 
-Directory | Get-ChildItem -File -Filter *.sql | ForEach-Object { $_ |Get-Content;
 "GO" } | out-file $(System.DefaultWorkingDirectory)/combined-script.sql

这将返回组合脚本,并在每个文件内容后附加“GO”

如何在每个文件内容之前添加文本?​​

最佳答案

ForEach-Object { "prepended text`n" + ($_ | Get-Content -raw) + "`nGO" }

也可以采用与附加 GO 相同的方式完成。

ForEach-Object {"prepended text"; $_ |Get-Content; "GO" }

关于Powershell 命令在每个文件之前添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66022780/

相关文章:

powershell - Try-catch 问题 powershell

PowerShell New-TimeSpan 友好地显示为天(s)小时(s)分钟(s)秒(s)

powershell - 无法比较创建日期和当前日期

Azure (Bicep) - 部署脚本 - 引用文件路径

azure - 需要 powershell 脚本来启用存储帐户和 key 保管库的诊断日志记录

.net - PowerShell 运行空间与 DLR

PowerShell HelpMessage 默认显示在参数中

powershell - 如何使用powershell进行多线程复制?

azure - Import-AzKeyVaultCertificate cmdlet 结果为 : Key not valid for user in specified state

asp.net-mvc - 从 PowerShell 将 Azure 网站发布到非根文件夹