Posted On July 2, 2019

PowerShell: Measure File Copying Time

kimconnect 0 comments
blog.KimConnect.com >> Codes >> PowerShell: Measure File Copying Time

The scripty:

$sourcesAndDestinations=@(
"C:\Users\kimconnect\Desktop\test\test1 C:\Users\kimconnect\Desktop\test\test2",
"C:\Users\kimconnect\Desktop\test\test2 C:\Users\kimconnect\Desktop\test\test3"
)

$testPath="C:\Users\kimconnect\Desktop\test\test1"
$switchesMirrorDirectories="/MIR /SEC /W:3 /FFT "
$dateStamp = Get-Date -Format "yyyy-MM-dd-hh-mm"
$currentPath=(Get-Item -Path ".\").FullName
$log="/LOG+:$currentPath\robocopy-log-$dateStamp.txt"

function createFiles{
for ($i=0; $i -lt 100; $i++){
fsutil file createnew "$testPath\$i.txt" 2000
}
}

function startRobocopy{
$totalTime=0;
foreach ($item in $sourcesAndDestinations){
$stopWatch= [System.Diagnostics.Stopwatch]::StartNew()
try{
invoke-expression "robocopy $item $switches $log";
}
catch{
continue;
}
$elapsedSeconds=$stopWatch.Elapsed.TotalSeconds;
"$item`: $elapsedSeconds seconds.";
$totalTime+=$elapsedSeconds;
}
"Total Time elapsed: $totalTime";
}

createFiles;
startRobocopy;

Output:

PS H:\> C:\Users\kimconnect\Desktop\unit-test.ps1
Error: The file exists.
Error: The file exists.
Error: The file exists.

Log File : H:\robocopy-log-2019-07-02-02-20.txt
C:\Users\kimconnect\Desktop\test\test1 C:\Users\kimconnect\Desktop\test\test2: 0.1134972 seconds.

Log File : H:\robocopy-log-2019-07-02-02-20.txt
C:\Users\kimconnect\Desktop\test\test2 C:\Users\kimconnect\Desktop\test\test3: 0.1132981 seconds.
Total Time elapsed: 0.2267953

Leave a Reply

Your email address will not be published. Required fields are marked *

Related Post

PowerShell: Automating Dynamics CRM Migration

This is the source code that has been used to move hundreds of Dynamics CRM…

HAProxy on CentOS 7

# Install HAProxy 1.8 using SCL repo yum install centos-release-scl yum install rh-haproxy18-haproxy rh-haproxy18-haproxy-syspaths  …

HTML: Basic Anatomy of A Page

Modern browsers discern the type of documents being loaded; thus, it is necessary to tag…