As you may know already, I released my first PowerPack for PowerGUI sometime last week. I am currently looking at various other features I want to add to this powerpack. One such feature is displaying progress information for each file transfer. While trying to figure out how I can implement this within PowerGUI Admin console, I came across a nice cmdlet Write-Progress which is used to show progress bars. Though this is a nice cmdliet, I can not directly use this in the powerpack.
However, I want to show how to use Write-Progress cmdlet with BITS file transfer.
To load BITS file transfer PowerShell cmdlets
Import-Module BitsTransfer
To start File Transfer
$bitsJob = Start-BitsTransfer -source http://download.microsoft.com/download/7/8/A/78ACCE4D-D1DD-4E54-80DA-928DCFD3AD6A/OfficeServer.exe -destination “C:\SharePoint” -Asynchronous
To view the progress,
$bitsJob | ForEach-Object {
while ($_.JobState -eq “Transferring”) {
$pctComplete = [int](($_.BytesTransferred * 100)/$_.BytesTotal);
clear-host;
write-progress -activity “File Transfer in Progress” -status “% Complete: $pctComplete” -percentcomplete $pctComplete
sleep 10;
}
}
This is it. You will see a progress bar at the top of PowerShell window as shown here.
Progress bar
If you close and open the PowerShell window, you will have to import Bits PowerShell module again and use the below command to get an instance of Bits file transfer Job
$bitJob = Get-BitsTransfer
You can now use the Write-Progress sample code as given above to monitor the progress.

{ 4 comments… read them below or add one }
You know, you can absolutely use Write-Progress in your PowerPack. PowerGUI 1.9.5 included support for Write-Progress, so as long as you’re using 1.9.5 or later you’ll see a progress bar with your BITS PowerPack using the same scripts you have shown above! If you try this out and have any difficulty, feel free to send any questions my way or just post them on the forums. Oh, and if you want to see an example, download the Org Chart PowerPack (in the Active Directory category). That uses Write-Progress when loading the Org Chart data, and it works just great!
Kirk out.
@Kirk
I tried this cmdlet with my powerpack but the behavior I saw is not something I want. Some of the file transfers can be quite large and may take a long time for the download to complete. Also, there will be more than one job running in the background. At present, usage of this cmdlet displays progress bar in a pop-up window — blocking all access to PowerGUI admin console. What I rather want is a way to display progress inline in the grid. Either a simple %progress number which can be refreshed automatically or a progress bar like write-progress one within the result grid for each BITS job. That would be cool. You see my point.
I see your point exactly, and that’s a great idea (that I’ll use in my own PowerPacks too!). I’ll make sure it gets put in the list of enhancement requests.
Enhancement request in PowerGUI..sounds super cool to me