简体   繁体   English

Powershell:Export-Csv的写进度

[英]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: 如果您知道$ 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). 去年某个时候,我发现我可以很容易地在任何使用ValueFromPipelineByPropertyName的命令上执行此操作(例如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 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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