Saturday, May 11, 2019

#92: How to forecast the time for certain task in Powershell?

This has always been a thought since I started using Windows 98. I remember the flying files avi file which used to pretend that actual file is flying from one folder to another. It used to appear as if the correct number of files are shown. Along with that it used to show how much time it will take. All in all, it was very amusing to see when I saw for the first time. I can't forget the Windows 98 themes in Plus. They all were full loaded with so much exciting stuffs into them. Under water them was the one which used to sound at every click and when application closes, it used to sound as if water went out.

Today's tip is not about Plus theme. This is all about forecasting the time which will be required to run a command. The time might vary based on situations, but you can get some guess about time. I will use measure-command cmdlet which will show you the time required to copy a file :

$SOURCE_FILE="C:\abc.zip"
$DESTINATION_FILE="D:\abc.zip"
(Measure-Command { Copy-Item $SOURCE_FILE $DESTINATION_FILE}).totalseconds

In my case, it output as :
1.540063

My file is around 50 MB and the location is same computer, so 1.5 seconds should be correct. I run the command as well and I suppose it took this much time.

This will work for all native commands only, you cannot run some other application and try to guess the time taken. Do not try to run something on SQL Server or any other application, this is good for native applications only.


Enjoy scripting!!

#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...