No Description

RobocopyGUI.ps1 10KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268
  1. # Load the Windows Forms assembly
  2. Add-Type -AssemblyName System.Windows.Forms
  3. # Load the Media Player assembly
  4. Add-Type -AssemblyName PresentationCore
  5. # Create a new form
  6. $form = New-Object System.Windows.Forms.Form
  7. $form.Text = "Robocopy GUI"
  8. $form.Size = New-Object System.Drawing.Size(600,500)
  9. $form.StartPosition = "CenterScreen"
  10. # Create a label for "Source Directory"
  11. $sourceLabel = New-Object System.Windows.Forms.Label
  12. $sourceLabel.Location = New-Object System.Drawing.Point(10,10)
  13. $sourceLabel.Size = New-Object System.Drawing.Size(150,40)
  14. $sourceLabel.Text = "Source Directory"
  15. $form.Controls.Add($sourceLabel)
  16. # Create a text field for "Source Directory"
  17. $sourceBox = New-Object System.Windows.Forms.TextBox
  18. $sourceBox.Location = New-Object System.Drawing.Point(170,10)
  19. $sourceBox.Size = New-Object System.Drawing.Size(300,40)
  20. $form.Controls.Add($sourceBox)
  21. # Create a dropdown menu for selecting a drive
  22. $driveMenu = New-Object System.Windows.Forms.ComboBox
  23. $driveMenu.Location = New-Object System.Drawing.Point(480,10)
  24. $driveMenu.Size = New-Object System.Drawing.Size(100,40)
  25. $driveMenu.DropDownStyle = "DropDownList"
  26. $form.Controls.Add($driveMenu)
  27. # Get the list of drives and their names
  28. $drives = Get-WmiObject -Class Win32_LogicalDisk | Select-Object -Property DeviceID, VolumeName
  29. # Add the drives to the dropdown menu
  30. foreach ($drive in $drives) {
  31. $driveMenu.Items.Add("$($drive.DeviceID) $($drive.VolumeName)")
  32. }
  33. # Create a button for "Copy from root"
  34. $rootButton = New-Object System.Windows.Forms.Button
  35. $rootButton.Location = New-Object System.Drawing.Point(10,60)
  36. $rootButton.Size = New-Object System.Drawing.Size(200,40)
  37. $rootButton.Text = "Copy from root"
  38. $form.Controls.Add($rootButton)
  39. # Create a button for "Copy from users directory"
  40. $usersButton = New-Object System.Windows.Forms.Button
  41. $usersButton.Location = New-Object System.Drawing.Point(220,60)
  42. $usersButton.Size = New-Object System.Drawing.Size(200,40)
  43. $usersButton.Text = "Copy from users directory"
  44. $form.Controls.Add($usersButton)
  45. # Create a label for "Destination Directory"
  46. $destinationLabel = New-Object System.Windows.Forms.Label
  47. $destinationLabel.Location = New-Object System.Drawing.Point(10,110)
  48. $destinationLabel.Size = New-Object System.Drawing.Size(150,40)
  49. $destinationLabel.Text = "Destination Directory"
  50. $form.Controls.Add($destinationLabel)
  51. # Create a text field for "Destination Directory"
  52. $destinationBox = New-Object System.Windows.Forms.TextBox
  53. $destinationBox.Location = New-Object System.Drawing.Point(170,110)
  54. $destinationBox.Size = New-Object System.Drawing.Size(300,40)
  55. $form.Controls.Add($destinationBox)
  56. # Create a button for "Copy to OldDrv"
  57. $oldDrvButton = New-Object System.Windows.Forms.Button
  58. $oldDrvButton.Location = New-Object System.Drawing.Point(480,110)
  59. $oldDrvButton.Size = New-Object System.Drawing.Size(100,40)
  60. $oldDrvButton.Text = "Copy to OldDrv"
  61. $form.Controls.Add($oldDrvButton)
  62. # Create a checkbox for "Use custom directory exclusions:"
  63. $xdCheckbox = New-Object System.Windows.Forms.CheckBox
  64. $xdCheckbox.Location = New-Object System.Drawing.Point(10,160)
  65. $xdCheckbox.Size = New-Object System.Drawing.Size(250,30)
  66. $xdCheckbox.Text = "Use custom directory exclusions:"
  67. $form.Controls.Add($xdCheckbox)
  68. # Create a text field for the /XD parameter
  69. $xdBox = New-Object System.Windows.Forms.TextBox
  70. $xdBox.Location = New-Object System.Drawing.Point(270,160)
  71. $xdBox.Size = New-Object System.Drawing.Size(300,30)
  72. $form.Controls.Add($xdBox)
  73. # Create a checkbox for "Use custom file exclusions:"
  74. $xfCheckbox = New-Object System.Windows.Forms.CheckBox
  75. $xfCheckbox.Location = New-Object System.Drawing.Point(10,200)
  76. $xfCheckbox.Size = New-Object System.Drawing.Size(250,30)
  77. $xfCheckbox.Text = "Use custom file exclusions:"
  78. $form.Controls.Add($xfCheckbox)
  79. # Create a text field for the /XF parameter
  80. $xfBox = New-Object System.Windows.Forms.TextBox
  81. $xfBox.Location = New-Object System.Drawing.Point(270,200)
  82. $xfBox.Size = New-Object System.Drawing.Size(300,30)
  83. $form.Controls.Add($xfBox)
  84. # Create a checkbox for "Disable standard exclusions:"
  85. $noStandardCheckbox = New-Object System.Windows.Forms.CheckBox
  86. $noStandardCheckbox.Location = New-Object System.Drawing.Point(10,240)
  87. $noStandardCheckbox.Size = New-Object System.Drawing.Size(250,30)
  88. $noStandardCheckbox.Text = "Disable standard exclusions"
  89. $form.Controls.Add($noStandardCheckbox)
  90. # Create a checkbox for "Log to file:"
  91. $logCheckbox = New-Object System.Windows.Forms.CheckBox
  92. $logCheckbox.Location = New-Object System.Drawing.Point(10,280)
  93. $logCheckbox.Size = New-Object System.Drawing.Size(250,30)
  94. $logCheckbox.Text = "Log to file:"
  95. $form.Controls.Add($logCheckbox)
  96. # Create a text field for the /LOG parameter
  97. $logBox = New-Object System.Windows.Forms.TextBox
  98. $logBox.Location = New-Object System.Drawing.Point(270,280)
  99. $logBox.Size = New-Object System.Drawing.Size(300,30)
  100. $form.Controls.Add($logBox)
  101. # Create a checkbox for "Log to C:\MCW\rbc.log"
  102. $mcwCheckbox = New-Object System.Windows.Forms.CheckBox
  103. $mcwCheckbox.Location = New-Object System.Drawing.Point(10,320)
  104. $mcwCheckbox.Size = New-Object System.Drawing.Size(250,30)
  105. $mcwCheckbox.Text = "Log to C:\MCW\rbc.log"
  106. $form.Controls.Add($mcwCheckbox)
  107. # Create a button for "Run"
  108. $runButton = New-Object System.Windows.Forms.Button
  109. $runButton.Location = New-Object System.Drawing.Point(10,360)
  110. $runButton.Size = New-Object System.Drawing.Size(200,40)
  111. $runButton.Text = "Run"
  112. $form.Controls.Add($runButton)
  113. # Define a function for running robocopy
  114. function Run-Robocopy {
  115. # Get the values from the text fields
  116. $source = $sourceBox.Text
  117. $destination = $destinationBox.Text
  118. $xd = $xdBox.Text
  119. $xf = $xfBox.Text
  120. $log = $logBox.Text
  121. # Check if the source and destination are valid
  122. if ((Test-Path $source)) {
  123. # Build the robocopy command
  124. $command = powershell.exe "robocopy $source $destination /E /COPY:DAT /DCOPY:DAT /XO /XJ /FP /ZB /ETA /w:1 /r:2"
  125. # Check if the custom directory exclusions are enabled
  126. if ($xdCheckbox.Checked) {
  127. # Add the /XD parameter
  128. $command += " /XD $xd"
  129. }
  130. # Check if the custom file exclusions are enabled
  131. if ($xfCheckbox.Checked) {
  132. # Add the /XF parameter
  133. $command += " /XF $xf"
  134. }
  135. # Check if the standard exclusions are disabled
  136. if ($noStandardCheckbox.Checked) {
  137. # Do nothing
  138. }
  139. else {
  140. # Add the standard directory and file exclusions
  141. $command += " /XD *Cache* *NVIDIACorp* *Spotify* *CacheStorage* *wpnidm* *FileHistory* *PrimeVideo* *Netflix_* *MobileSync* *CrashReporter* *Temporary Internet Files* *GRBData*"
  142. $command += " /XF *.dll *.bin *.loggz *.odlgz"
  143. }
  144. # Check if the log to file is enabled
  145. if ($logCheckbox.Checked) {
  146. # Add the /LOG parameter
  147. $command += " /LOG:$log"
  148. }
  149. # Check if the log to C:\MCW\rbc.log is enabled
  150. if ($mcwCheckbox.Checked) {
  151. # Get the current timestamp
  152. $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
  153. # Add the /LOG+ parameter
  154. $command += " /LOG+:C:\MCW\rbc.log"
  155. # Check if the C:\MCW directory exists
  156. if (Test-Path "C:\MCW") {
  157. # Do nothing
  158. }
  159. else {
  160. # Create the C:\MCW directory
  161. New-Item -Path "C:\MCW" -ItemType Directory
  162. }
  163. # Check if the log file exists
  164. if (Test-Path "C:\MCW\rbc.log") { # Do nothing
  165. }
  166. else {
  167. # Create the log file
  168. New-Item -Path "C:\MCW\rbc.log" -ItemType File
  169. }
  170. # Add the timestamp to the log file
  171. Set-ItemProperty -Path "C:\MCW\rbc.log" -Value "$timestamp"
  172. }
  173. # Create a new powershell window to run the robocopy command
  174. $newWindow = "powershell -NoExit -Command `"$command; pause`""
  175. # Execute the new window command
  176. Invoke-Expression $newWindow
  177. # Play Ring06.wav from the system Media folder
  178. $player = New-Object System.Windows.Media.MediaPlayer
  179. $player.Open("C:\Windows\Media\Ring06.wav")
  180. $player.Play()
  181. }
  182. else {
  183. # Show an error message
  184. [System.Windows.Forms.MessageBox]::Show("Invalid source or destination directory.", "Error", "OK", "Error")
  185. }
  186. }
  187. # Define a function for copying from users directory
  188. function Copy-From-Users {
  189. # Get the selected drive from the dropdown menu
  190. $drive = $driveMenu.SelectedItem
  191. # Check if the drive is valid
  192. if ($drive) {
  193. # Get the drive letter
  194. $driveLetter = $drive.Substring(0,2)
  195. # Set the source directory to the users directory of the drive
  196. $sourceBox.Text = "$driveLetter\Users"
  197. }
  198. else {
  199. # Show an error message
  200. [System.Windows.Forms.MessageBox]::Show("Please select a drive.", "Error", "OK", "Error")
  201. }
  202. }
  203. # Define a function for copying to OldDrv
  204. function Copy-To-OldDrv {
  205. # Set the destination directory to C:\OldDrv
  206. $destinationBox.Text = "C:\OldDrv"
  207. # Check if the source directory contains the string "Users"
  208. if ($sourceBox.Text -match "Users") {
  209. # Append "\Users" to the destination directory
  210. $destinationBox.Text += "\Users"
  211. }
  212. }
  213. # Define a function for copying from root
  214. function Copy-From-Root {
  215. # Get the selected drive from the dropdown menu
  216. $drive = $driveMenu.SelectedItem
  217. # Check if the drive is valid
  218. if ($drive) {
  219. # Get the drive letter
  220. $driveLetter = $drive.Substring(0,2)
  221. # Set the source directory to the root of the drive
  222. $sourceBox.Text = "$driveLetter\"
  223. }
  224. else {
  225. # Show an error message
  226. [System.Windows.Forms.MessageBox]::Show("Please select a drive.", "Error", "OK", "Error")
  227. }
  228. }
  229. # Add a click event handler for the run button
  230. $runButton.Add_Click({ Run-Robocopy })
  231. # Add a click event handler for the copy from users directory button
  232. $usersButton.Add_Click({ Copy-From-Users })
  233. # Add a click event handler for the copy to OldDrv button
  234. $oldDrvButton.Add_Click({ Copy-To-OldDrv })
  235. # Add a click event handler for the copy from root button
  236. $rootButton.Add_Click({ Copy-From-Root })
  237. # Show the form
  238. $form.ShowDialog()

Powered by TurnKey Linux.