# Load the Windows Forms assembly Add-Type -AssemblyName System.Windows.Forms # Load the Media Player assembly Add-Type -AssemblyName PresentationCore # Create a new form $form = New-Object System.Windows.Forms.Form $form.Text = "Robocopy GUI" $form.Size = New-Object System.Drawing.Size(600,500) $form.StartPosition = "CenterScreen" # Create a label for "Source Directory" $sourceLabel = New-Object System.Windows.Forms.Label $sourceLabel.Location = New-Object System.Drawing.Point(10,10) $sourceLabel.Size = New-Object System.Drawing.Size(150,40) $sourceLabel.Text = "Source Directory" $form.Controls.Add($sourceLabel) # Create a text field for "Source Directory" $sourceBox = New-Object System.Windows.Forms.TextBox $sourceBox.Location = New-Object System.Drawing.Point(170,10) $sourceBox.Size = New-Object System.Drawing.Size(300,40) $form.Controls.Add($sourceBox) # Create a dropdown menu for selecting a drive $driveMenu = New-Object System.Windows.Forms.ComboBox $driveMenu.Location = New-Object System.Drawing.Point(480,10) $driveMenu.Size = New-Object System.Drawing.Size(100,40) $driveMenu.DropDownStyle = "DropDownList" $form.Controls.Add($driveMenu) # Get the list of drives and their names $drives = Get-WmiObject -Class Win32_LogicalDisk | Select-Object -Property DeviceID, VolumeName # Add the drives to the dropdown menu foreach ($drive in $drives) { $driveMenu.Items.Add("$($drive.DeviceID) $($drive.VolumeName)") } # Create a button for "Copy from root" $rootButton = New-Object System.Windows.Forms.Button $rootButton.Location = New-Object System.Drawing.Point(10,60) $rootButton.Size = New-Object System.Drawing.Size(200,40) $rootButton.Text = "Copy from root" $form.Controls.Add($rootButton) # Create a button for "Copy from users directory" $usersButton = New-Object System.Windows.Forms.Button $usersButton.Location = New-Object System.Drawing.Point(220,60) $usersButton.Size = New-Object System.Drawing.Size(200,40) $usersButton.Text = "Copy from users directory" $form.Controls.Add($usersButton) # Create a label for "Destination Directory" $destinationLabel = New-Object System.Windows.Forms.Label $destinationLabel.Location = New-Object System.Drawing.Point(10,110) $destinationLabel.Size = New-Object System.Drawing.Size(150,40) $destinationLabel.Text = "Destination Directory" $form.Controls.Add($destinationLabel) # Create a text field for "Destination Directory" $destinationBox = New-Object System.Windows.Forms.TextBox $destinationBox.Location = New-Object System.Drawing.Point(170,110) $destinationBox.Size = New-Object System.Drawing.Size(300,40) $form.Controls.Add($destinationBox) # Create a button for "Copy to OldDrv" $oldDrvButton = New-Object System.Windows.Forms.Button $oldDrvButton.Location = New-Object System.Drawing.Point(480,110) $oldDrvButton.Size = New-Object System.Drawing.Size(100,40) $oldDrvButton.Text = "Copy to OldDrv" $form.Controls.Add($oldDrvButton) # Create a checkbox for "Use custom directory exclusions:" $xdCheckbox = New-Object System.Windows.Forms.CheckBox $xdCheckbox.Location = New-Object System.Drawing.Point(10,160) $xdCheckbox.Size = New-Object System.Drawing.Size(250,30) $xdCheckbox.Text = "Use custom directory exclusions:" $form.Controls.Add($xdCheckbox) # Create a text field for the /XD parameter $xdBox = New-Object System.Windows.Forms.TextBox $xdBox.Location = New-Object System.Drawing.Point(270,160) $xdBox.Size = New-Object System.Drawing.Size(300,30) $form.Controls.Add($xdBox) # Create a checkbox for "Use custom file exclusions:" $xfCheckbox = New-Object System.Windows.Forms.CheckBox $xfCheckbox.Location = New-Object System.Drawing.Point(10,200) $xfCheckbox.Size = New-Object System.Drawing.Size(250,30) $xfCheckbox.Text = "Use custom file exclusions:" $form.Controls.Add($xfCheckbox) # Create a text field for the /XF parameter $xfBox = New-Object System.Windows.Forms.TextBox $xfBox.Location = New-Object System.Drawing.Point(270,200) $xfBox.Size = New-Object System.Drawing.Size(300,30) $form.Controls.Add($xfBox) # Create a checkbox for "Disable standard exclusions:" $noStandardCheckbox = New-Object System.Windows.Forms.CheckBox $noStandardCheckbox.Location = New-Object System.Drawing.Point(10,240) $noStandardCheckbox.Size = New-Object System.Drawing.Size(250,30) $noStandardCheckbox.Text = "Disable standard exclusions" $form.Controls.Add($noStandardCheckbox) # Create a checkbox for "Log to file:" $logCheckbox = New-Object System.Windows.Forms.CheckBox $logCheckbox.Location = New-Object System.Drawing.Point(10,280) $logCheckbox.Size = New-Object System.Drawing.Size(250,30) $logCheckbox.Text = "Log to file:" $form.Controls.Add($logCheckbox) # Create a text field for the /LOG parameter $logBox = New-Object System.Windows.Forms.TextBox $logBox.Location = New-Object System.Drawing.Point(270,280) $logBox.Size = New-Object System.Drawing.Size(300,30) $form.Controls.Add($logBox) # Create a checkbox for "Log to C:\MCW\rbc.log" $mcwCheckbox = New-Object System.Windows.Forms.CheckBox $mcwCheckbox.Location = New-Object System.Drawing.Point(10,320) $mcwCheckbox.Size = New-Object System.Drawing.Size(250,30) $mcwCheckbox.Text = "Log to C:\MCW\rbc.log" $form.Controls.Add($mcwCheckbox) # Create a button for "Run" $runButton = New-Object System.Windows.Forms.Button $runButton.Location = New-Object System.Drawing.Point(10,360) $runButton.Size = New-Object System.Drawing.Size(200,40) $runButton.Text = "Run" $form.Controls.Add($runButton) # Define a function for running robocopy function Run-Robocopy { # Get the values from the text fields $source = $sourceBox.Text $destination = $destinationBox.Text $xd = $xdBox.Text $xf = $xfBox.Text $log = $logBox.Text # Check if the source and destination are valid if ((Test-Path $source)) { # Build the robocopy command $command = powershell.exe "robocopy $source $destination /E /COPY:DAT /DCOPY:DAT /XO /XJ /FP /ZB /ETA /w:1 /r:2" # Check if the custom directory exclusions are enabled if ($xdCheckbox.Checked) { # Add the /XD parameter $command += " /XD $xd" } # Check if the custom file exclusions are enabled if ($xfCheckbox.Checked) { # Add the /XF parameter $command += " /XF $xf" } # Check if the standard exclusions are disabled if ($noStandardCheckbox.Checked) { # Do nothing } else { # Add the standard directory and file exclusions $command += " /XD *Cache* *NVIDIACorp* *Spotify* *CacheStorage* *wpnidm* *FileHistory* *PrimeVideo* *Netflix_* *MobileSync* *CrashReporter* *Temporary Internet Files* *GRBData*" $command += " /XF *.dll *.bin *.loggz *.odlgz" } # Check if the log to file is enabled if ($logCheckbox.Checked) { # Add the /LOG parameter $command += " /LOG:$log" } # Check if the log to C:\MCW\rbc.log is enabled if ($mcwCheckbox.Checked) { # Get the current timestamp $timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss" # Add the /LOG+ parameter $command += " /LOG+:C:\MCW\rbc.log" # Check if the C:\MCW directory exists if (Test-Path "C:\MCW") { # Do nothing } else { # Create the C:\MCW directory New-Item -Path "C:\MCW" -ItemType Directory } # Check if the log file exists if (Test-Path "C:\MCW\rbc.log") { # Do nothing } else { # Create the log file New-Item -Path "C:\MCW\rbc.log" -ItemType File } # Add the timestamp to the log file Set-ItemProperty -Path "C:\MCW\rbc.log" -Value "$timestamp" } # Create a new powershell window to run the robocopy command $newWindow = "powershell -NoExit -Command `"$command; pause`"" # Execute the new window command Invoke-Expression $newWindow # Play Ring06.wav from the system Media folder $player = New-Object System.Windows.Media.MediaPlayer $player.Open("C:\Windows\Media\Ring06.wav") $player.Play() } else { # Show an error message [System.Windows.Forms.MessageBox]::Show("Invalid source or destination directory.", "Error", "OK", "Error") } } # Define a function for copying from users directory function Copy-From-Users { # Get the selected drive from the dropdown menu $drive = $driveMenu.SelectedItem # Check if the drive is valid if ($drive) { # Get the drive letter $driveLetter = $drive.Substring(0,2) # Set the source directory to the users directory of the drive $sourceBox.Text = "$driveLetter\Users" } else { # Show an error message [System.Windows.Forms.MessageBox]::Show("Please select a drive.", "Error", "OK", "Error") } } # Define a function for copying to OldDrv function Copy-To-OldDrv { # Set the destination directory to C:\OldDrv $destinationBox.Text = "C:\OldDrv" # Check if the source directory contains the string "Users" if ($sourceBox.Text -match "Users") { # Append "\Users" to the destination directory $destinationBox.Text += "\Users" } } # Define a function for copying from root function Copy-From-Root { # Get the selected drive from the dropdown menu $drive = $driveMenu.SelectedItem # Check if the drive is valid if ($drive) { # Get the drive letter $driveLetter = $drive.Substring(0,2) # Set the source directory to the root of the drive $sourceBox.Text = "$driveLetter\" } else { # Show an error message [System.Windows.Forms.MessageBox]::Show("Please select a drive.", "Error", "OK", "Error") } } # Add a click event handler for the run button $runButton.Add_Click({ Run-Robocopy }) # Add a click event handler for the copy from users directory button $usersButton.Add_Click({ Copy-From-Users }) # Add a click event handler for the copy to OldDrv button $oldDrvButton.Add_Click({ Copy-To-OldDrv }) # Add a click event handler for the copy from root button $rootButton.Add_Click({ Copy-From-Root }) # Show the form $form.ShowDialog()