将Listview项目导出为CSV文件

时间:2017-07-21 14:37:20

标签: powershell csv listview

我有一个包含5列的列表视图,我需要导出到CSV。

enter image description here

这就是它的样子。我环顾四周,无法找到解决问题的可行办法。

这就是我将数据添加到列表视图的方式:

$searcher = [adsisearcher]"(samaccountname=$Content)"
foreach ($DirectReportDN in $searcher.FindAll().Properties.directreports)
{
    $DirectReport = [adsi]"LDAP://$DirectReportDN"
    $Username = $DirectReport.Properties.samaccountname
    $Associate = $DirectReport.Properties.name
    $Title = $DirectReport.Properties.title
    $Mgr = $DirectReport.Properties.extensionattribute6
    $Dept = $DirectReport.Properties.department

    Add-ListViewItem -ListView $listview2 -Items $Username -Group $listview2.Groups[0] -SubItems "$Associate", "$Title", "$Mgr", "$Dept"
}

任何帮助将不胜感激,我一直在研究这个问题。谢谢!

1 个答案:

答案 0 :(得分:0)

将项目导出为CSV:

$ListViewName.Items | Export-CSV -Path "some\path.csv" -NoTypeInformation