我准备了一个PowerShell脚本来导出CSV格式的系统用户列表。 该脚本可以用单个标题行(顶部的标题行)输出具有Export-csv的用户列表。
但是我的要求是在我的文件中重复两次标题行。 在PowerShell 3.0中使用“Append”很容易实现(例如$ header | out-file $ filepath -Append)我们的服务器环境正在运行PowerShell 1.0。 所以我做不到。 有没有解决办法? 我不能自己手动添加它。
谢谢。
你可以做的是:
Export-Csv写入CSV Get-Content将内容读回到一个variables中 喜欢这个:
# Path to your file $File = "C:\My\File.csv" # Write the CSV file $Data | Export-Csv $File # Read it back as plain text $CSV = Get-Content $File # Add the header line at the start $CSV = $Header + $CSV # Write it all back to the CSV file $CSV | Set-Content $File