Advertisement
Guest User

Robocopy Powershell

a guest
Oct 10th, 2017
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #Settings
  2. $Host.UI.RawUI.WindowTitle = 'Robocopy migration script'
  3. $datum = Get-Date -Format "MM-dd-yyyy-hh-mm-ss"
  4. $options = @("/S", "/MT[:4]") # Robocopy arguments for mor see robocopy /?
  5.  
  6. #Path settings
  7. $src = "C:\Test" # Source Path
  8. $dest = "C:\Test2d" # Destination Path
  9. $logpath = $dest+"\" # Logfile Path
  10. $logname = "Logfile_"+$datum+".log" # Logfile Name
  11. $log = @($logpath+$logname)  
  12.  
  13. #Exclusion
  14. $excludeFilename = @("*Kopie*.*", "~$*.*", "*x0*", "*copy*.*") # Exclude file with given name
  15. $excludeFolder = @("Archiv", "alt") # Exclude folder with given name
  16.  
  17. #Extension Filters
  18. $word = @("*.docx", "*.docm", "*.doc") # Word extension that will be copied
  19. $excel = @("*.xlsx", "*.xlsm", "*.xls") # Excel extension that will be copied
  20. $powerpoint = @("*.pptx", "*.pptm", "*.ppt") # PowerPoint extension that will be copied
  21. $visio = @("*.vsdx", "*.vsdm", "*.vsd") # Visio extension that will be copied
  22. $pdf = @("*.pdf") # PDF extension that will be copied
  23. #$tempeplates = @("*.dotx", "*dot", "*.xltx", "*xlt", "*.potx", "*pot") # Templates extension that coud be copied too
  24.  
  25. #Start
  26. Write-Output `n "Start Robocopy Script in 5 Seconds"`n
  27. Start-Sleep -s 5
  28.  
  29. #Check if source and destination path exist
  30. If (-not (Test-Path $src)) {
  31. Write-Output "The path '$src' does not exist. Script has stopped!"`n
  32.   break
  33. }
  34. If (-not (Test-Path $dest)) {
  35. new-item -path $dest -type "directory" | Out-Null
  36. Write-Output "The folder '$dest' has been created"`n
  37. }
  38.  
  39. #Create Logfile
  40. new-item -path $log -type "file" | Out-Null
  41. Write-Output "The $logname has been created in $logpath"`n
  42.  
  43.  
  44. #Create command
  45. $cmdArgs = @($src, $dest, $word, $excel, $visio, $powerpoint, $pdf, $options)
  46.  
  47. #Run robocopy command
  48. Write-Output "Copy files from '$src' to '$dest'"`n
  49. robocopy @cmdArgs /XF $excludeFilename /XD $excludeFolder /LOG:$log  | Out-Null
  50.  
  51. #Exit
  52. Write-Output "Job complete"
  53. Start-Sleep -s 15
  54. $host.Exit
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement