Forum Discussion

MP21260's avatar
MP21260
Copper Contributor
Feb 02, 2022
Solved

How to add Export-Csv to a script

Hello !   I'm studying PowerShell and I'd like to add an Export-Csv command for a script. However I couldn't understand how to put this command in it. Here the script :    $emplacement = "D:\DO...
  • Leavii's avatar
    Leavii
    Mar 09, 2022

    Hello,

    At the end of your for loop (within the loop) you would want to add your $file | export-csv... (line 32). As $files is being overwritten each time within the loop, you are going to only receive one output outside of the loop... Your last output which executes after your for loop.

    I haven't tried your code personally, but typically when I export to CSV I create an object and export that as such.

     

     

    $object = New-Object -TypeName psObject
    $object | Add-member -MemberType NoteProperty -Name "Example" -value $variable
    $object | Export-Csv -Path $logFile -Force -Encoding ASCII -Append -NoTypeInformation

     

     

Resources