[英]Add columns for CSV output
I have this PowerShell query listed below and I require the headers to be machine, path, filewalkmethod
我在下面列出了此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
}
}
Sample output: 样本输出:
nas01e,E$,Windows
Updated Query I'm using: 我正在使用的更新查询:
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 }
Untested but this should work: 未经测试,但这应该可以工作:
foreach($s in $fs){
$s.Volumes | Select-Object @{n='Machine'; e={$s.ServerName}}, Share, FileWalkMethod | Export-CSV D:\data\splunk\otl_varonis\otl_varonis_monitoring.csv -NoTypeInformation -Append
}
Note that the parameter -Append
for Export-Csv
was introduced with PowerShell v3. 请注意,PowerShell v3引入了参数-Append
for Export-Csv
。 To make this compatible with earlier versions you could pipeline the loop: 为了使它与早期版本兼容,您可以管道循环:
$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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.