Skip to main content
deleted 185 characters in body
Source Link
LotPings
  • 328
  • 1
  • 7
> Q:\Test\2019\08\23\sf_226703.ps1                                                                                                  /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE

desc                     src                          dst                          log
----                     ---                          ---                          ---
main fileshares          \\server1\D$\Shares          \\server2\D$                 fileshare
Citrix User Store Shares \\server1\D$\CitrixUserStore \\server2\E$\CitrixUserStore ctxusrshare
Citrix User Redir Shares \\server1\D$\CitrixUserRedir \\server2\E$\CitrixUserRedir ctxusrredir


Starting job main fileshares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\Shares" "\\server2\D$" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\fileshare_2019-08-23-20-59.txt"
Starting job Citrix User Store Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserStore" "\\server2\E$\CitrixUserStore" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrshare_2019-08-23-20-59.txt"
Starting job Citrix User Redir Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserRedir" "\\server2\E$\CitrixUserRedir" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrredir_2019-08-23-20-59.txt"
> Q:\Test\2019\08\23\sf_226703.ps1                                                                                                  /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE

desc                     src                          dst                          log
----                     ---                          ---                          ---
main fileshares          \\server1\D$\Shares          \\server2\D$                 fileshare
Citrix User Store Shares \\server1\D$\CitrixUserStore \\server2\E$\CitrixUserStore ctxusrshare
Citrix User Redir Shares \\server1\D$\CitrixUserRedir \\server2\E$\CitrixUserRedir ctxusrredir


Starting job main fileshares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\Shares" "\\server2\D$" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\fileshare_2019-08-23-20-59.txt"
Starting job Citrix User Store Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserStore" "\\server2\E$\CitrixUserStore" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrshare_2019-08-23-20-59.txt"
Starting job Citrix User Redir Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserRedir" "\\server2\E$\CitrixUserRedir" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrredir_2019-08-23-20-59.txt"
> Q:\Test\2019\08\23\sf_226703.ps1

desc                     src                          dst                          log
----                     ---                          ---                          ---
main fileshares          \\server1\D$\Shares          \\server2\D$                 fileshare
Citrix User Store Shares \\server1\D$\CitrixUserStore \\server2\E$\CitrixUserStore ctxusrshare
Citrix User Redir Shares \\server1\D$\CitrixUserRedir \\server2\E$\CitrixUserRedir ctxusrredir


Starting job main fileshares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\Shares" "\\server2\D$" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\fileshare_2019-08-23-20-59.txt"
Starting job Citrix User Store Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserStore" "\\server2\E$\CitrixUserStore" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrshare_2019-08-23-20-59.txt"
Starting job Citrix User Redir Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserRedir" "\\server2\E$\CitrixUserRedir" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrredir_2019-08-23-20-59.txt"
Source Link
LotPings
  • 328
  • 1
  • 7

  • If you don't want an external csv file,
    use an internal one - simulated with a here string and ConvertFrom-Csv
  • in a date format specifier upper case MM are for month, minutes are lower case mm
  • the following script has several variable names shorted to keep line length down.
  • the final command is only echoed / commented out.

## Q:\Test\2019\08\23\sf_226703.ps1
# sets the files to exclude 
$defaultDirExclusionSet = '"$Recycle.Bin" "System Volume Information"'

#options for robocopy
$RoboOpts = "/MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD $defaultDirExclusionSet /NP /TEE"

# simulate external csv with a here string and ConvertFrom-Csv
$RCJobs = @'
desc,src,dst,log
"main fileshares","\\server1\D$\Shares","\\server2\D$","fileshare"
"Citrix User Store Shares","\\server1\D$\CitrixUserStore","\\server2\E$\CitrixUserStore","ctxusrshare"
"Citrix User Redir Shares","\\server1\D$\CitrixUserRedir","\\server2\E$\CitrixUserRedir","ctxusrredir"
'@ -split '\r?\n' | ConvertFrom-Csv

$RCJobs | Format-Table -Auto

##### launch all at once.  fix the first line before using.
foreach($J in $RCJobs){
    Write-Host -Fore Green "Starting job $($J.desc)"
    $Args = '"{0}" "{1}" {2} /log+:"C:\robocopylogs\{3}_{4:yyyy-MM-dd-HH-mm}.txt"' -f `
           $J.src,$J.dst,$RoboOpts,$J.log,(Get-Date)
    "Start-Process robocopy.exe -ArgumentList $Args"
    #Start-Process robocopy.exe -ArgumentList $Args  
}

Sample output without executing RoboCopy.

> Q:\Test\2019\08\23\sf_226703.ps1                                                                                                  /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE

desc                     src                          dst                          log
----                     ---                          ---                          ---
main fileshares          \\server1\D$\Shares          \\server2\D$                 fileshare
Citrix User Store Shares \\server1\D$\CitrixUserStore \\server2\E$\CitrixUserStore ctxusrshare
Citrix User Redir Shares \\server1\D$\CitrixUserRedir \\server2\E$\CitrixUserRedir ctxusrredir


Starting job main fileshares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\Shares" "\\server2\D$" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\fileshare_2019-08-23-20-59.txt"
Starting job Citrix User Store Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserStore" "\\server2\E$\CitrixUserStore" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrshare_2019-08-23-20-59.txt"
Starting job Citrix User Redir Shares
Start-Process robocopy.exe -ArgumentList "\\server1\D$\CitrixUserRedir" "\\server2\E$\CitrixUserRedir" /MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD "$Recycle.Bin" "System Volume Information" /NP /TEE /log+:"C:\robocopylogs\ctxusrredir_2019-08-23-20-59.txt"