添加CSV输出列

时间:2018-01-03 15:20:17

标签: powershell csv

我在下面列出了此PowerShell查询,我要求标题为machine, path, filewalkmethod

$fs = Get-FileServer
foreach ($s in $fs) {
    foreach ($share in $s.Volumes) {
        ($s.Servername, $share.Share, $share.FileWalkMethod) -join "," |
            Out-File -Append D:\data\splunk\otl_varonis\otl_varonis_monitoring.csv
    }
}

示例输出:

nas01e,E$,Windows 

我正在使用的更新查询:

Import-Module -Name VaronisManagement 
Connect-Idu 
$fs = Get-FileServer 
      foreach($s in $fs){
         $s.Volumes | Select-Object @{n='ServerName'; e={$s.ServerName}}, Share, FileWalkMethod |
         Export-CSV D:\data\splunk\otl_varonis\otl_varonis_monitoring_test.csv
            -NoTypeInformation -NoClobber }

1 个答案:

答案 0 :(得分:4)

未经测试,但这应该有效:

-Append

请注意,Export-Csv的参数$fs | ForEach-Object { $machine = $_.ServerName $_.Volumes | Select-Object @{n='Machine';e={$machine}}, Share, FileWalkMethod } | Export-Csv D:\data\splunk\otl_varonis\otl_varonis_monitoring.csv -NoType 是随PowerShell v3引入的。为了使其与早期版本兼容,您可以管道循环:

{{1}}