【发布时间】:2019-01-28 20:00:50
【问题描述】:
我是 Powershell 的新手,我已经让我的批处理文件能够将结果输出到屏幕上。我希望将文件导出为 CSV,以便能够将其放入可按目录排序的 Excel 文件,然后按日期排序。
我可以使用Out-File 命令来编写基本文件,但 CSV 输出似乎无法正常工作。我只得到一个 CSV 文件,其中包含每条记录的 Length。
有人可以帮忙吗?提前致谢。
这是我尝试过的:
#--Change the name with directory you want to visit --#
$dir_to_look="E:\xPression\CustomerData\xPressionECR\*\XMLDATA"
#--You may change the number of days of your choice --#
$TwoDays=$(Get-Date).AddDays(-2)
Remove-Item E:\xPression\CustomerData\xPressionECR\ReportOutput\Report.csv
#--Find the files which are modified or created within last 2 days --#
Get-Childitem $dir_to_look *.xml -Recurse | `
where-object {!($_.psiscontainer)} | `
where { $_.LastWriteTime -gt $TwoDays } | `
ForEach-Object { "$($_.LastWriteTime) , $($_.Fullname)"| Out-File -LiteralPath E:\xPression\CustomerData\xPressionECR\ReportOutput\Report.csv -Append}
【问题讨论】:
-
鉴于您使用
$_.psiscontainer,我们可以假设您仅限于Powershell-v2吗?如果您将 Powershell-Version 添加为标签会有所帮助:) -
我的版本信息:PSVersion 4.0
标签: powershell csv powershell-4.0