Tuesday, January 21, 2020

Reporting Script Duration

Currently working on a migration project where the source and target environments are quite large. We have a script that queries all mailboxes in the source and matches them to a target object.

The script takes 10-12 hours to run. We're making tweaks and want to see the effect, but we're not going to watch the script to verify the time to complete.

Here's a little bit of PowerShell that you can add to any script to measure the time to complete:

 #Start of Script  
 $start = Get-Date  
 
 
 #End of script  
 $end = Get-Date  
 
 # Calculate elapsed time  
 # Output in format hh:mm:ss  
 Write-Host “Script run time”  
 Write-Host $($end-$start)