I have a powershell script that is currently running every 4 hours via task scheduler. It cleans a drive and when it's done it fires off an email to me telling me what it moved and where and the amount of time it took to perform this task.
However, I seem to be having issues with the time it displays at the end. I recently got an email that it took 4 minutes, when I know that it took closer to 30 minutes.
The basic structure looks like this:
$StopWatch = new-object system.diagnostics.stopwatch
$StopWatch.Start()
Do { All this stuff }
While(This condition is false)
$StopWatch.Stop()
$Minutes = $StopWatch.elapsed.minutes
What am I missing here? This thing is just reading the system time and then comparing it to the current time whenever .elapsed
is accessed right?