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: How To Disable and/or Stop Windows Service

Disable and Stop Using Native Command 'Set-Service' # To disable service as well as stopping…

Basic HTML and HTML5: Add a Submit Button to a Form

<h2>CatPhotoApp</h2><main><p>Click here to view more <a href="#">cat photos</a>.</p><a href="#"><img src="https://bit.ly/fcc-relaxing-cat" alt="A cute orange cat lying…

Setting Up FTP on CentOS 5.3

Install VSFTPD yum -y install vsftpd   Configure: vim /etc/vsftpd/vsftpd.conf ------------------- anonymous_enable=NO // line 12:…