简体   繁体   中英

Powershell: Write-Progress of Export-Csv

This is a snipping of my code:

$alltheupdates | Export-Csv filename.csv

Is it possible to write the progress of an export?

If you know how many objects are in $alltheupdates:

0..($alltheupdates.count-1) | foreach {
    $percent = ($_/$alltheupdates.count)*100
    Write-Progress -Activity 'exporting to csv' -Status "$percent % Complete" -CurrentOperation "Exporting item # $($_+1)" -PercentComplete $percent
    $alltheupdates[$_]
} | Export-Csv filename.csv

I figured out sometime last year that I can do this pretty easily on any command that takes ValueFromPipelineByPropertyName (like Export-CSV). This will do the trick. It will not include the %, because to calculate % you have to know the total number of items you'll be exporting.

Get-ChildItem |    
    Export-Csv -Path $home\files.csv -inputObject { $_; Write-Progress "Exporing to CSV" "$($_) " } 

Hope this Helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM