以下是我的代码示例:
$logpath = @(gci -path "c:\logs")
foreach ($i in $logpath)
{
[array]$n += ($i.tostring()).trimend(".log")
[array]$t += ($i.tostring()).lastwritetime
}
$obj = new-object psobject
$obj | Add-Member -MemberType NoteProperty -Name Logname -Value $n
$obj | Add-Member -MemberType NoteProperty -Name LastWriteTime -Value $t
$i | export-csv c:\temp\logs.csv
以下是输出的样子:
Name,LastWriteTime
----,-------------
Value1...,Value1
以下是我希望它的样子:
Name,LastWriteTime
Value1,Value1
Value2,Value2