0

I have this PowerShell query listed below and I require the headers to be 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 }

1 Answer 1

4

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. 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
Sign up to request clarification or add additional context in comments.

7 Comments

That did provide the headers in the output but only returned one value with it, there should be over 400 results.
@dcraven Edited to add -Append, like in your Out-File
What version of Powershell are you on? Also you can try -NoClobber instead of -Append
Please update your question to add the code that you are running now and the error that you are getting. This feels like a syntax error.
@dcraven All versions of PowerShell reside in that directory. From what I heard it's an artifact of when Microsoft considered parallel installations of different PowerShell versions (same as the .ps1 extension). To identify the version of PowerShell you have installed enter $PSVersionTable in a PowerShell console. Most likely you're still on v2, since the -Append parameter for Export-Csv was introduced with PowerShell v3.
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.