Powershell – Robocopy with speed test timer

Run a robocopy and display the elapsed time.

#--- VARIABLES
    #--- IP OR HOSTNAME
    $workstation = "192.168.79.83"
    #--- FOLDERS
        #--- SOURCE FOLDER
        $sourceFolder = "C:\CyberTransport\TFTP\deleteme\"
        #--- DESTINATION FOLDER
        $destinationFolder = "\\$workstation\c$\copytestdeleteme"
    #--- LOG FILE
    $logPath = "$($env:USERPROFILE)\Desktop\Robocopy-Logs\"

#--- LOG File 
    #--- IF PATH DOES NOT EXIST, CREATE IT
    if(!(Test-Path -Path $logPath )){
        New-Item -Force -ItemType directory -Path $logPath
    }

#--- CONFIRM HOST IS UP
if (test-Connection -Count 1 -Cn $workstation -quiet) {
    Write-Host "$workstation is online" -ForegroundColor Green
} else {
    Write-Host "$workstation is not online" -ForegroundColor Red
		}


         pause


#--- SET START TIME
$stopWatch = [system.diagnostics.stopwatch]::startNew()
$stopWatch.Start()

#--- COPY DIRECTORY
if (test-Connection -Count 1 -Cn $workstation -quiet) {

    #-MIRROR ALL ITEMS AND ALLOW ONLY 2 RETRIES
    robocopy $sourceFolder $destinationFolder /MIR /R:2 /log:$logPath$workstation.txt /tee

} else {
    "$workstation is not online"
		}

#--- DISPLAY TIME THE SCRIPT TOOK TO RUN APPEND TO LOG FILE
$stopWatch.Stop()
Write-Host "Elapsed Runtime:" $stopWatch.Elapsed.Minutes "minutes and" $stopWatch.Elapsed.Seconds "seconds." -ForegroundColor Cyan
Write-Output 'Elapsed Runtime:' $stopWatch.Elapsed.Minutes 'minutes and' $stopWatch.Elapsed.Seconds 'seconds.' | Out-File $logPath$workstation.txt -Append -Encoding ascii

#--- REMOVE COPIED ITEM
Remove-Item \\$workstation\c$\copytestdeleteme\*

 

Leave a Reply

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