Is there a way of adding a windows type progress bar to a powershell script running Dism?

白昼怎懂夜的黑 提交于 2019-12-13 03:05:07

问题


I am trying to add a windows type progress bar to a powershell script running Dism. I am having difficulty with thw win32_service. Would anyone know how to do this?

dism /Apply-Image /ImageFile:Z:\path\wim.wim /Index:1 /ApplyDir:C:\


回答1:


Agree with Mathias R. Jessen point.

Making and using PowerShell progress bar(s) is a well documented thing in the PowerShell built-in help files and all over the web. Here is a goo article with several examples regarding 'How to Make a PowerShell Progress Bar'

The author provides and shows via gifs of single

For ($i=0; $i -le 100; $i++) {
    Start-Sleep -Milliseconds 20
    Write-Progress -Activity "Counting to 100" -Status "Current Count: $i" -PercentComplete $i -CurrentOperation "Counting ..."
}

and nested progress bars.

For ($i=0; $i -le 100; $i++) {
    Start-Sleep -Milliseconds 1
    Write-Progress -Id 1 -Activity "First Write Progress" -Status "Current Count: $i" -PercentComplete $i -CurrentOperation "Counting ..."

    For ($j=0; $j -le 100; $j++) {
        Start-Sleep -Milliseconds 1
        Write-Progress -Id 2 -Activity "Second Write Progress" -Status "Current Count: $j" -PercentComplete $j -CurrentOperation "Counting ..."
    }
}

Also, any reason you are using WQL vs the built-in PowerShell cmdlets for looking at services?

Get-Service | Where-Object {$_.Status -eq "Running"}

As well as why you'd want a progress bar for that, since the return s immediate, and the outputting just the name? Which you can just do ...

(Get-Service | Where-Object {$_.Status -eq "Running"}).Name

or

Get-Service | Where-Object {$_.Status -eq "Running"} | Select-Object -Property Name

Each will have a return that is very fast, that a progress bar is moot unless you intentionally slow it down with the Start-Sleep cmdlet, but there should be little reason for that.

If you are looking for a script with a progress bar for DISM. See this discussion and pre-built sample here:

Generate a GUI progress bar for DISM or ImageX

The accepted answer provided is a long block of code, that is too long to post here:



来源:https://stackoverflow.com/questions/55692868/is-there-a-way-of-adding-a-windows-type-progress-bar-to-a-powershell-script-runn

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!