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

Discover FSMO roles

Option ExplicitDim WSHNetwork, objArgs, ADOconnObj, bstrADOQueryString, RootDom, RSObjDim FSMOobj,CompNTDS, Computer, Path, HelpTextSet WSHNetwork = CreateObject("WScript.Network")Set…

PowerShell: Quickly Add Users into Groups on a List of Computers

$newVmNames=@( 'SERVER0001', 'SERVER0002' ) $newUsers=@( 'domain\user1' ) $groupNames='Administrators','Remote Desktop Users' $newVmNames|%{ invoke-command -computername $_ {…

PowerShell: How To Invoke Rest Method with RingCentral Rest API

[string]$restApiTokenUrl="https://platform.ringcentral.com/restapi/oauth/token" [string]$restApiUrl="https://platform.ringcentral.com/restapi/v1.0/account/~/extension?page=1" [string]$username='15555555555' [string]$password='PASSWORDHERE' [string]$extension='100' [string]$appKey='APPKEYHERE' # Part 1: Obtain Rest-API Token / Authorization function…