CopyTool - V

After using the CopyTool over the weekend I found that the tool will not handle copy jobs larger then 50gb reliably and since I built the tool to do that specifically I decided it needed  to be revised. The result of my revision is CopyTool - V , version is built on top of Microsoft Robust File Copy built into all versions of  windows. The tools gives you the option to create a log file, copy only the folder structure, exclude files based on a wildcard, exclude empty folders and move the target content rather then just copy it. I have provided a help button right in the GUI as well as a stop button for the copy process.

You can get your copy of CopyTool - V from the Tools Download page. Below is the script that makes the tool work.

This script is used to perform large copy jobs

The script provides you a GUI to enter a source and destination for your copy process. The target and destination should be folders,
the script will copy the content of the source folder into the destination folder.

Created By: Kris Gross
Twitter: @kmgamd


Function Generate-Form 
    #Needed for the form to show
    Add-Type -AssemblyName System.Windows.Forms
    Add-Type -AssemblyName System.Drawing
    $tooltip = New-Object System.Windows.Forms.ToolTip
    $Form = New-Object System.Windows.Forms.Form
    $Form.Size = New-Object System.Drawing.Size(660,510)
    $Form.Text = "CopyTool - V"
    $Form.StartPosition = "CenterScreen"
    $Icon = [system.drawing.icon]::ExtractAssociatedIcon($PSScriptRoot + "\CopyTool.exe")
    $Form.MinimizeBox = $False
    $Form.MaximizeBox = $False
    # $Form.WindowState = "Normal"
    $Form.SizeGripStyle = "Hide"
    $Form.Icon = $Icon

    #Display popup help 
        Switch ($ 
            "CheckBoxLog"  {$tip = "Create a log file"}
            "Source" {$tip = "Source folder you want to copy"}
            "Destination" {$tip = "Where you want the source folder content to be copied to"}
            "FSOnlyCheckBox" {$tip = "Check this box to only copy the folder structure, No files will be copied"}
            "ExcludeEmptyFolders" {$tip = "Exclude empty folders"}
            "MOVECheckBox" {$tip = "Moves all files and folders from source to destination"}
            "xfcheckbox" {$tip = "Allows you to specify files to be excluded, us * as a wildcard"}
    #sets the help button
    $HelpButton = New-Object System.Windows.Forms.Button
    $HelpButton.Location = New-Object System.Drawing.Point(15,145)
    $HelpButton.Size = New-Object System.Drawing.Size(220,23)
    $HelpButton.Text = "HELP"

    #sets the donate button
    $DonateButton = New-Object System.Windows.Forms.Button
    $DonateButton.Location = New-Object System.Drawing.Point(570,0)
    $DonateButton.Size = New-Object System.Drawing.Size(75,20)
    $DonateButton.Text = "Donate"

    #sets the copy button
    $CopyButton = New-Object System.Windows.Forms.Button
    $CopyButton.Location = New-Object System.Drawing.Point(15,90)
    $CopyButton.Size = New-Object System.Drawing.Size(100,50)
    $CopyButton.Name = "Copy Button"
    $CopyButton.Text = "Start"
    $CopyButton.BackColor = "ForestGreen"

    #sets the stop button
    $StopButton = New-Object System.Windows.Forms.Button
    $StopButton.Location = New-Object System.Drawing.Point(135,90)
    $StopButton.Size = New-Object System.Drawing.Size(100,50)
    $StopButton.Name = "Copy Stop"
    $StopButton.Text = "Stop"
    $StopButton.BackColor = "IndianRed"

    #label for source box
    $SourceBoxLabel = New-Object System.Windows.Forms.Label
    $SourceBoxLabel.Location = New-Object System.Drawing.Point(15,10)
    $SourceBoxLabel.Size = New-Object System.Drawing.Size(280,13) 
    $SourceBoxLabel.Text = "Source:"

    #source box
    $SourceBox = New-Object System.Windows.Forms.TextBox
    $SourceBox.Name = "Source"
    $SourceBox.Location = New-Object System.Drawing.Size(15,25) 
    $SourceBox.Size = New-Object System.Drawing.Size(250,25)
    $SourceBox.Font = "Courier New"
    $SourceBox.Text = $Source

    #Browse button for source 
    $BrowseSourceButton = New-Object System.Windows.Forms.Button
    $BrowseSourceButton.Location = New-Object System.Drawing.Point(280,25)
    $BrowseSourceButton.Size = New-Object System.Drawing.Size(75,20)
    $BrowseSourceButton.Text = "Browse"

    #Destination label 
    $DestinationBoxLabel = New-Object System.Windows.Forms.Label
    $DestinationBoxLabel.Location = New-Object System.Drawing.Point(15,50)
    $DestinationBoxLabel.Size = New-Object System.Drawing.Size(280,13) 
    $DestinationBoxLabel.Text = "Destination:"

    #Destination Box 
    $DestinationBox = New-Object System.Windows.Forms.TextBox 
    $DestinationBox.Name = "Destination"
    $DestinationBox.Location = New-Object System.Drawing.Size(15,65) 
    $DestinationBox.Size = New-Object System.Drawing.Size(250,25)
    $DestinationBox.Font = "Courier New"
    $DestinationBox.Text = $Destination

    #Browse button for destination
    $BrowseDestinationButton = New-Object System.Windows.Forms.Button
    $BrowseDestinationButton.Location = New-Object System.Drawing.Point(280,65)
    $BrowseDestinationButton.Size = New-Object System.Drawing.Size(75,20)
    $BrowseDestinationButton.Text = "Browse"

    #Output box
    $outputBox = New-Object System.Windows.Forms.textBox 
    $outputBox.Location = New-Object System.Drawing.Size(15,175) 
    $outputBox.Size = New-Object System.Drawing.Size(610,290)
    $outputBox.BackColor = "Black"
    $outputBox.forecolor = "YellowGreen"
    $outputBox.MultiLine = $True
    $outputBox.ReadOnly = $True
    $outputBox.Scrollbars = "Both"
    $outputBox.Font = "Courier New"

    #Check box for creating a log file
    $checkboxLog = New-Object System.Windows.Forms.checkbox
    $checkboxLog.Name = "CheckBoxLog"
    $checkboxLog.Location = New-Object System.Drawing.Size(5,15)
    $checkboxLog.Size = New-Object System.Drawing.Size(45,20)
    $checkboxLog.Text = "Log"

    #Check box for file structure only 
    $FSOnlyCheckBox = New-Object System.Windows.Forms.checkbox
    $FSOnlyCheckBox.Name = "FSOnlyCheckBox"
    $FSOnlyCheckBox.Location = New-Object System.Drawing.Size(50,15)
    $FSOnlyCheckBox.Size = New-Object System.Drawing.Size(90,20)
    $FSOnlyCheckBox.Text = "FS Only"

    #Check box for the S switch, used to exclude empty folders
    $ScheckBox = New-Object System.Windows.Forms.checkbox
    $ScheckBox.Name = "ExcludeEmptyFolders"
    $ScheckBox.Location = New-Object System.Drawing.Size(5,35)
    $ScheckBox.Size = New-Object System.Drawing.Size(45,20)
    $ScheckBox.Text = "/S"
    #Check box for moving source to destination
    $MoveCheckBox = New-Object System.Windows.Forms.checkbox
    $MoveCheckBox.Name = "MOVECheckBox"
    $MoveCheckBox.Location = New-Object System.Drawing.Size(50,35)
    $MoveCheckBox.Size = New-Object System.Drawing.Size(90,20)
    $MoveCheckBox.Text = "Move"

    #Check box for xf switch 
    $xfCheckBox = New-Object System.Windows.Forms.checkbox
    $xfCheckBox.Name = "xfCheckBox"
    $xfCheckBox.Location = New-Object System.Drawing.Size(5,55)
    $xfCheckBox.Size = New-Object System.Drawing.Size(40,20)
    $xfCheckBox.Text = "/xf:"
    $xfCheckBox.Add_CheckStateChanged({IF($xfCheckBox.Checkstate -eq "Checked") {$xfbox.Enabled = $true} IF($xfCheckBox.Checkstate -eq "unchecked") {$xfbox.Enabled = $false}})
    #Imput box for the xf switch options
    $xfbox = New-Object System.Windows.Forms.textBox 
    $xfbox.Location = New-Object System.Drawing.Size(45,55) 
    $xfbox.Size = New-Object System.Drawing.Size(85,20)
    $xfbox.Enabled = $False
    $xfbox.Font = "Courier New"

    #group box for the copy options
    $OptionsGroupBox = New-Object System.Windows.Forms.GroupBox
    $OptionsGroupBox.Location = New-Object System.Drawing.Size(375,5) 
    $OptionsGroupBox.size = New-Object System.Drawing.Size(190,80) 
    $OptionsGroupBox.text = "Options" 
    #Adds items to the form 

    #Adds items to the copy options group box

    #shows the form
    [void] $Form.ShowDialog()

#Action for donate button
Function Click_Donate
#action for help button
Function Click_Help
    $outputBox.AppendText("CopyTool - V`n")
    $outputBox.AppendText("Created By: Kris Gross`n")
    $outputBox.AppendText("Twitter: @kmgamd`n")
    $outputBox.AppendText("Updates can be found at:`n")
    $outputBox.AppendText("This version of CopyTool uses robocopy to copy files and folders.`n")
    $outputBox.AppendText("How To Use:`n")
    $outputBox.AppendText("1. Browse to or type the path to the content you want to copy or move`n")
    $outputBox.AppendText("2. Browse to or type the path to where you want the content to be copied or moved to`n")
    $outputBox.AppendText("3. Choose the options that meet your needs. Hover your mouse over the option for a desctiption of what it dose`n")
    $outputBox.AppendText("4. Click Start to start the copy process`n")
#action for Browse for Source 
Function Click_BrowseSource
    [System.Reflection.Assembly]::LoadWithPartialName("") | Out-Null     
    $SourceForm = New-Object System.Windows.Forms.FolderBrowserDialog
    $SourceForm.Rootfolder = "Desktop"
    $SourceForm.Description = "Select Folder"
    $Source = $SourceForm.SelectedPath
#action for Browse for destination
Function Click_BrowseDestination
    param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
    [System.Reflection.Assembly]::LoadWithPartialName("") | Out-Null     
    $destinationForm = New-Object System.Windows.Forms.FolderBrowserDialog
    $destinationForm.Rootfolder = $RootFolder
    $destinationForm.Description = $Description
    $Destination = $DestinationForm.SelectedPath
#action for the stop button
function Click_Stop
        Stop-Process -Name robocopy -Force
#actions for copy button
Function Click_Copy
    #Sets the filter text to null so the same filter dosnt get used on a second copy job
    $FilterFiles = $null
    #if the log check box is checked create a log file
    if ($checkboxLog.Checked) {$switchLog = "/Log:$PSScriptRoot\copy.log"}
    #if FSonly check box sets needs swtches to copy only the file structure 
    if ($FSOnlyCheckBox.Checked) 
        $FilterFiles = "*"
        $switchMIR = "/MIR" 
        $switchXF = "/xf"
    #if move check box checked sets switches needs to move all files and folders
    if ($MoveCheckBox.Checked) 
        $switchMOVE = "/MOVE"
        $switchE = "/E"
    #if the s check box checked sets the switch needs 
    If ($SCheckBox.Checked) {$switchS = "/S"}
    #if the xf check box is checked sets the xf switch and reads the filter fromt he xfbox
    IF ($xfCheckBox.Checked) 
        $switchXF = "/xf"
        $FilterFiles = $xfbox.text

    #Clears the outputbo so its easy to read after each copy job
    #sets the source for the Source box
    $Source = $SourceBox.Text
    #sets the Destination for the Destination box
    $Destination = $DestinationBox.text
    #runs teh copy process with the options you selected  
    Robocopy.exe $Source $Destination /J /R:0 /W:0 $switchLog $switchMIR $switchXF $FilterFiles $switchE $switchS $switchMOVE /TEE | foreach-Object {
        $ErrorActionPreference = "silentlycontinue"
        $outputBox.AppendText($_ + "`r`n")
        [void] [System.Windows.Forms.Application]::DoEvents()
    if ($checkboxLog.Checked) {$outputBox.AppendText("Your log file can be found at $PSScriptRoot\Copy.log`n")}


Popular posts from this blog

SCCM Task Sequence GUI - How to set up the TS to work with a GUI

SCCM Applications vs. SCCM Packages: Understanding the Key Differences

How to Deploy a Windows 10 Servicing update as a Application