Capture cmdlet progress bars

This topic contains 5 replies, has 4 voices, and was last updated by Profile photo of Windows LiveUser82 Windows LiveUser82 2 years, 4 months ago.

  • Author
    Posts
  • #17208
    Profile photo of Corey Thomas
    Corey Thomas
    Participant

    I'm working on making a GUI for some winPE stuff to make it easier on our system admins. Right now I have the basic ps script working well. When I execute the dism cmdlets, a progress bar pops up in it's own window. I'd like to bind that progress bar to my own progress bar in my forms. Is there a way to do that?

  • #17213
    Profile photo of Rob Simmers
    Rob Simmers
    Participant

    Can you provide a more specific example with the cmdlets that are producing the progress bars? You can probably show no progress and generate your own progress in the form. Another question is if you launch the cmdlets in a console, does the progress stay in the window or does it spawn a child process?

  • #17218
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Well, you should be able to prevent the default progress bars from popping up by setting the $ProgressPreference variable to SilentlyContinue. However, getting the data into your own form would depend on how you are executing the PowerShell code. If you're executing code using the System.Management.Automation.PowerShell class, then it's easy; you have access to the Progress stream, and can bind listeners to its DataAdded event (PowerShell.Streams.Progress.DataAdded; see [url]http://msdn.microsoft.com/en-us/library/system.management.automation.psdatastreams.progress(v=vs.85).aspx[/url] and [url]http://msdn.microsoft.com/en-us/library/dd144531(v=vs.85).aspx[/url].

    If you're just executing a script in powershell.exe, and building your own forms from there, I'm not sure how you'd intercept those ProgressRecords, off the top of my head.

  • #17225
    Profile photo of Corey Thomas
    Corey Thomas
    Participant

    I'm doing the GUI in PowerShell Studio 2012. Here is an example some lines that pops up a progress bar:

    Mount-WindowsImage -ImagePath $DestinationWimPath -Path $TempMountPath -Index 1

    Add-WindowsPackage -Path $TempMountPath -PackagePath "C:\Program Files (x86)\Windows Kits\8.1\Assessment and Deployment Kit\Windows Preinstallation Environment\x86\WinPE_OCs\WinPE-WMI.cab"

    I want to bind that progress bar to a progress bar in my GUI so I can show progress of each step. I know I could suppress all of the progress bars and show my own for each step, but I want to show the progress of the actual step, not the overall process. If powershell is outputting a progress bar, certainly there is a way I can get that info and bind to it.

  • #17230
    Profile photo of Dave Wyatt
    Dave Wyatt
    Moderator

    Not sure what to tell you. If you search for "PowerShell Progress Stream", you'll find all sorts of examples that use the approach I mentioned, using the S.M.A. PowerShell object, then monitoring its Streams.Progress collection for new data. This is what the PowerShell host is doing to show you the progress bars in the first place, in fact.

    I didn't find any examples of a way to accomplish this when you're just executing a cmdlet normally from within the PowerShell console.

  • #17299
    Profile photo of Windows LiveUser82
    Windows LiveUser82
    Participant

    If you've plenty of time on your hands, another way would be to execute these actions via the DISM API, which has a callback, DismProgressCallback . It's a Win32 API if i recall though, so won't be fun to setup.

You must be logged in to reply to this topic.