This topic contains 5 replies, has 4 voices, and was last updated by
July 16, 2014 at 3:12 pm #17208ParticipantPoints: 0Rank: Member
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?
July 16, 2014 at 4:36 pm #17213ParticipantPoints: 159Rank: 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?
July 16, 2014 at 5:43 pm #17218MemberPoints: 0Rank: Member
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 http://msdn.microsoft.com/en-us/library/system.management.automation.psdatastreams.progress(v=vs.85).aspx and http://msdn.microsoft.com/en-us/library/dd144531(v=vs.85).aspx.
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.
July 17, 2014 at 5:31 am #17225ParticipantPoints: 0Rank: Member
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.
July 17, 2014 at 6:18 am #17230MemberPoints: 0Rank: Member
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.
July 18, 2014 at 1:41 pm #17299ParticipantPoints: 0Rank: Member
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.
The topic ‘Capture cmdlet progress bars’ is closed to new replies.