首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用Powershell捕获DISM输出并通过进度条反映状态?

如何使用Powershell捕获DISM输出并通过进度条反映状态?
EN

Stack Overflow用户
提问于 2019-09-26 17:31:16
回答 1查看 1.2K关注 0票数 2

我想用这个方法捕捉一张图片

代码语言:javascript
运行
复制
DISM.exe /capture-ffu /imagefile=e:\WinOEM.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0 /description:"Windows 10 FFU"

参考资料:

代码语言:javascript
运行
复制
https://docs.microsoft.com/en-us/windows-hardware/manufacture/desktop/deploy-windows-using-full-flash-update--ffu

在powershell中,我是这样使用的

代码语言:javascript
运行
复制
& DISM.exe /capture-ffu /imagefile=e:\WinOEM.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0 /description:"Windows 10 FFU"

并在捕获时显示命令窗口。我可以在进行捕获的同时创建一个类似进度条的GUI吗?

谢谢你的建议。

我已经创建了这个PowerShell脚本。但在执行此命令时

代码语言:javascript
运行
复制
$Result = & DISM.exe /capture-ffu /imagefile=E:\TEST\capture.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0

进度条不是开始或显示进度,它只是显示为空(白条)。请给我任何建议。

代码语言:javascript
运行
复制
Add-Type -assembly System.Windows.Forms

## -- Create The Progress-Bar
$ObjForm = New-Object System.Windows.Forms.Form
$ObjForm.Text = "Image Capturing"
$ObjForm.WindowState = 'Maximized'
$ObjForm.BackColor = "White"

$ObjForm.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedSingle
$ObjForm.StartPosition = [System.Windows.Forms.FormStartPosition]::CenterScreen

## -- Create The Label
$ObjLabel = New-Object System.Windows.Forms.Label
$ObjLabel.Text = "Starting. Please wait ... "
$ObjLabel.Left = 5
$ObjLabel.Top = 10
$ObjLabel.Width = 500 - 20
$ObjLabel.Height = 15
$ObjLabel.Font = "Tahoma"
## -- Add the label to the Form
$ObjForm.Controls.Add($ObjLabel)

$PB = New-Object System.Windows.Forms.ProgressBar
$PB.Name = "PowerShellProgressBar"
$PB.Value = 0
$PB.Style="Continuous"

$System_Drawing_Size = New-Object System.Drawing.Size
$System_Drawing_Size.Width = 700 - 40
$System_Drawing_Size.Height = 20
$PB.Size = $System_Drawing_Size
$PB.Left = 5
$PB.Top = 40
$ObjForm.Controls.Add($PB)

## -- Show the Progress-Bar and Start The PowerShell Script
$ObjForm.Show() | Out-Null
$ObjForm.Focus() | Out-NUll
$ObjLabel.Text = "Starting. Please wait ... "
$ObjForm.Refresh()

Start-Sleep -Seconds 1

$Result = & DISM.exe /capture-ffu /imagefile=E:\TEST\capture.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0
$Counter = 0
ForEach ($Item In $Result) {
    ## -- Calculate The Percentage Completed
    $Counter++
    [Int]$Percentage = ($Counter/$Result.Count)*100
    $PB.Value = $Percentage
    $ObjLabel.Text = "Capturing The Image"
    $ObjForm.Refresh()
    Start-Sleep -Milliseconds 150
    # -- $Item.Name
    "`t" + $Item.Path

}

$ObjForm.Close()
Write-Host "`n"

已更新

我认为如果它完成了,DISM.exe将无法报告。我必须让进度条一直滚动到这个过程结束。

代码语言:javascript
运行
复制
& DISM.exe /capture-ffu /imagefile=e:\WinOEM.ffu /capturedrive=\\.\PhysicalDrive0 /name:disk0 /description:"Windows 10 FFU"

任何人都可以给我点子。

EN

回答 1

Stack Overflow用户

发布于 2019-09-26 18:54:37

Write-Progress对你来说足够了吗?

代码语言:javascript
运行
复制
.....
ForEach ($Item In $Result) {
    $Counter++
    [Int]$Percentage = ($Counter/$Result.Count)*100
    Write-Progress -activity "Completion" -status "Status" -PercentComplete $Percentage   
}
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/58113715

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档