我编写了一个构建自定义对象并将其导出到 CSV 文件的脚本:
$reg = Get-ItemProperty HKLM:\SOFTWARE\McAfee\DLP\Agent | Select-Object agentversion
$date = Get-ItemProperty 'C:\Program Files\McAfee' | Select-Object {$_.LastWriteTime}
$date86 = Get-ItemProperty 'C:\Program Files (x86)\McAfee'| Select-Object {$_.LastWriteTime}
New-Object -TypeName pscustomobject -Property @{
"Number1"=$reg
"Number2"=$date86
"Number3"=$date } | export-csv -Path C:\****\desktop\stuff.csv -NoTypeInformation
生成的 CSV 文件中的数据行是:
"@{AgentVersion=9.4.112.22}","@{$ .LastWriteTime=5/6/2016 6:02:32 AM}","@{$ .LastWriteTime=7/5/2016 8:34:01 PM }"
是否有可能摆脱不需要的@{<name>=...}
包装?