简体   繁体   English

powershell命令执行进度?

[英]powershell command execution progress?

So I am doing some file operations using powershell using a combination of commands. 因此,我使用命令组合使用powershell进行了一些文件操作。

eg: 例如:

import-csv $DataFile -Delimiter "`t" | ConvertTo-Csv -Delimiter '|' -NoTypeInformation | % { $_ -replace '"', ""} | out-file $PipeFile
(get-content $DataFile -ReadCount 1000) -replace '\x00','' | set-content $DataFile

and a few more file manipulations. 以及其他一些文件操作。

These manipulations are happening on huge data files which take 40-60 minutes to execute. 这些操作发生在庞大的数据文件上,执行需要40-60分钟。 So, we wanted to see some kind of "progress bar or progress meter" that will allow me to identify how much is completed vs pending. 因此,我们希望看到某种“进度条或进度表”,这将使我能够确定完成与未完成的数量。 Or something verbose that can be put on the screen? 还是可以在屏幕上显示一些冗长的内容?

write-progress is something I thought would help me, but, how I am interpreting it is better suited for "loops". 我认为写进度会有所帮助,但是,我如何解释它更适合“循环”。

Any pointers are appreciated. 任何指针表示赞赏。

Write-Progress IS more suited to loops, however you can still use it. Write-Progress IS更适合循环,但是您仍然可以使用它。

I've just attempted to edit your code so that it uses foreach loops to write out progress. 我刚刚尝试编辑您的代码,以便它使用foreach循环写出进度。

You will have to test this in a safe environment. 您将必须在安全的环境中对此进行测试。

# Grabbing pipe data
# ------------------

$PipeData = Import-CSV $DataFile -delim "`t" | ConvertTo-Csv -delim '|' -notype

ForEach ($line in $PipeData)
{
    $New_PipeData += $line -replace '"', ""
    Write-Progress `
      -id 1 `
      -Activity "Creating New Pipe Data" `
      -Status "Converting..." `
      -PercentComplete ($progress/100))
    $progress += $line.length
}

$New_PipeData | Out-File $PipeFile

# Writing out to data file
# ------------------------

ForEach ($block in ((gc $DataFile -ReadCount 1000) -replace '\x00',''))
{
    $block | set-content $DataFile
    Write-Progress `
      -id 2 `
      -Activity "Outputting blocks" `
      -Status "Writing..." `
      -PercentComplete ($progress/100)
    $progress += $block.length
}

There is a high chance that you will need to tweak this to suit your needs. 您很有可能需要对其进行调整以满足您的需求。

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

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