Powershell – Robocopy to Shared Folders on Multiple Workstations

Map a folder on multiple workstation and copy local data to it.

#--- "workstations" is a text file containing the hostnames of the computers.
$workstations = "standalone-workstations.txt"


(Get-Content $workstations) -notmatch '^#' | foreach {
    if (test-Connection -Count 1 -Cn $_ -quiet) {
        Write-Host "$_ is online" -ForegroundColor Green
    } else {
        Write-Host "$_ is not online" -ForegroundColor Red -NoNewline
        Write-Host " - Make sure the Laptop has not gone night-night." -ForegroundColor Yellow 
	}
}

         pause




(Get-Content $workstations) -notmatch '^#' | foreach {
    if (test-Connection -Count 1 -Cn $_ -quiet) {

        #--- CONNECT TO SHARE
        net use \\$_\cybertransport /user:$_\admin P@ssw0rd123
        
        #-MIRROR ALL ITEMS AND ALLOW ONLY 2 RETRIES
        robocopy C:\CyberTransport\ \\$_\cybertransport /MIR /R:2

        net use \\$_\cybertransport /delete

    } else {
        "$_ is not online"
}
}

 

Leave a Reply

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