Thursday, October 30, 2014

#30 : Using Progressbar with a purpose

Progressbar is simply achieved in Powershell with Write-progress cmdlet. This cmdlet can be used with below example -

Write-Progress -Activity "File-Copy" -PercentComplete 55 -Status "Something" -Id 1

Running the above command in Powershell prompt is not meaningful, it will not display anything. I saw so many articles about Write-Progess, but all of them are using a dummy example to use Progressbar, so I am presenting an example which will show you a real utilization of Write-progress.
Example of using Write-Progress

The example demonstrates the utilization of Write-Progress. In this example, we will copy files from a source location to a destination and we will display progessbar for this. The status of progressbar will show the status of task. It does not show the file-copy status of individual file, but it shows the percent status of file-copy task as a whole.
I will use SOURCE_PATH and TARGET_PATH variables and if you are testing it on your computer, you must change the path. For god sake, do not use a disk where operating system is installed and do not use a disk which has low disk space. Anyways, a professional will not do such mistake.





Isn't this easy to use Write-Progress in your other scripts!
Enjoy Scripting!

No comments:

Post a Comment

#112: How to handle xml document in Powershell?

 In PowerShell, you can handle XML data using various cmdlets and methods provided by the .NET Framework. Here's a basic guide on how to...