Export-csv creates an empty csv file, why??


in code below,  export-csv creates empty csv file, empty mean file contains type info , rest commas, no data.

when out-string or export-clixml, works fine. missing work export-csv??

using powershell 2.0.

     $volumes | {$_.capacity -gt 0} | foreach { $_ | add-member -passthru noteproperty frag

         ($_.defraganalysis().defraganalysis.totalpercentfragmentation) } |

         select @{n="server";e={$_.systemname}}, driveletter,label,capacity,freespace, 

            @{n="percfree";e={"{0,9:n0}" -f (($_.freespace/1gb)/($_.capacity/1gb)*100)}},

            frag, @{n="infodate";e={$dt} | export-csv "mycsv.csv"

 

thanks!!


--acg

finally got it, this:

 

$volumes | {$_.capacity -gt 0} | foreach { $_ | add-member -name frag -membertype noteproperty -value $_ -force -passthru

         ($_.defraganalysis().defraganalysis.totalpercentfragmentation) } |

         select @{n="server";e={$_.systemname}}, driveletter,label,capacity,freespace, 

            @{n="percfree";e={"{0,9:n0}" -f (($_.freespace/1gb)/($_.capacity/1gb)*100)}},

            frag, @{n="infodate";e={$dt}} | export-csv "mycsv.csv"

 

the key add-member line. although not quite sure why other output types worked in original code , not export-csv??


--acg


Windows Server  >  Windows PowerShell



Comments

Popular posts from this blog

Error: 0x80073701 when trying to add Print Services Role in Windows 2012 Standard

Windows 2016 RDS event 1306 Connection Broker Client failed to redirect the user... Error: NULL

Como saber quien entro a mi PC por la Red