I am trying to get better at Powershell and was wondering if I could get some advice on how to make this code more efficient/cleaner/anything.
This code is intended to launch three batch windows running robocopy at the same time with unique log names.
I looked into using a foreach loop but wasn't sure how I could do that with so many unique variables. Thinking back, I probably could have imported each source, destination and log name into a CSV though but this may have been cleaner/better because it's all in one file instead.
# sets the files to exclude $defaultDirExclusionSet = '"$Recycle.Bin" "System Volume Information"' # setting the filename perameter so that we have some timestamps. $filedate = "$(get-date -format 'yyyy-MM-dd-HH-MM')" # we can remove the HH and MM later... have this on now for testing. #options for robocopy $RoboOptions = "/MIR /COPY:DATSOU /ZB /R:1 /W:5 /XD $defaultDirExclusionSet /NP /TEE" #main fileshares $source = "\\server1\D$\Shares" $destination = "\\server2\D$" $logname = "fileshare" #Citrix User Store Shares $source1 = "\\server1\D$\CitrixUserStore" $destination1 = "\\server2\E$\CitrixUserStore" $logname1 = "ctxusrshare" #Citrix User Redir Shares $source2 = "\\server1\D$\CitrixUserRedir" $destination2 = "\\server2\E$\CitrixUserRedir" $logname2 = "ctxusrredir" ##### launch all at once. fix the first line before using. Start-Process robocopy.exe -ArgumentList "$($source) $($destination) $($RoboOptions.split(' ')) /log+:c:\robocopylogs\$($logname)_$($filedate).txt" Start-Process robocopy.exe -ArgumentList "$($source1) $($destination1) $($RoboOptions.split(' ')) /log+:c:\robocopylogs\$($logname1)_$($filedate).txt" Start-Process robocopy.exe -ArgumentList "$($source2) $($destination2) $($RoboOptions.split(' ')) /log+:c:\robocopylogs\$($logname2)_$($filedate).txt"