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: Maintain Chocolatey Applications

This current version has some bugs... Review these other codes for some ideas on fixing...…

Basic HTML and HTML5: Uncomment HTML

<!--<h1>Hello World</h1><h2>CatPhotoApp</h2><p>Kitty ipsum dolor sit amet, shed everywhere shed everywhere stretching attack your ankles chase…

ipToHostname

Get-Content C:\Users\kimconnect\Desktop\ipList.txt | ForEach-Object {([system.net.dns]::GetHostByAddress($_)).hostname}