CopyTool - V 3.0.0.0

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 3.0.0.0 , version 3.0.0.0 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 3.0.0.0 from the Tools Download page. Below is the script that makes the tool work.





<#
.SYNOPSIS
This script is used to perform large copy jobs

.DESCRIPTION
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.

.NOTES
Created By: Kris Gross
Contact: Krisgross@sccmtst.com
Twitter: @kmgamd

.LINK
http://www.sccmtst.com/
#>

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 3.0.0.0"
    $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 
    $ShowHelp={
        Switch ($this.name) 
        {
            "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"}
        }
        $tooltip.SetToolTip($this,$tip)
    } 
    
    #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"
    $HelpButton.Add_Click({Click_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"
    $DonateButton.Add_Click({Click_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"
    $CopyButton.Add_Click({Click_Copy})

    #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"
    $StopButton.Add_Click({Click_Stop})

    #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
    $SourceBox.add_MouseHover($ShowHelp)

    #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"
    $BrowseSourceButton.Add_Click({Click_BrowseSource})

    #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
    $DestinationBox.add_MouseHover($ShowHelp)

    #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"
    $BrowsedestinationButton.Add_Click({Click_BrowseDestination})

    #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.Checked=$False
    $CheckBoxLog.add_MouseHover($ShowHelp)
    $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.Checked=$False
    $FSOnlyCheckBox.add_MouseHover($ShowHelp)
    $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.Checked=$False
    $ScheckBox.add_MouseHover($ShowHelp)
    $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.Checked=$False
    $MoveCheckBox.add_MouseHover($ShowHelp)
    $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.Checked=$False
    $xfCheckBox.add_MouseHover($ShowHelp)
    $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 
    $Form.Controls.Add($DonateButton)
    $Form.Controls.Add($outputBox)
    $Form.Controls.Add($HelpButton)
    $Form.Controls.Add($SourceBox)
    $Form.Controls.Add($DestinationBox)
    $Form.Controls.Add($DestinationBoxLabel)
    $Form.Controls.Add($SourceBoxLabel)
    $Form.Controls.Add($CopyButton)
    $Form.Controls.Add($StopButton)
    $Form.Controls.Add($BrowseSourceButton)
    $Form.Controls.Add($BrowseDestinationButton)
    $Form.Controls.Add($OptionsGroupBox)

    #Adds items to the copy options group box
    $OptionsGroupBox.Controls.Add($checkboxLog)
    $OptionsGroupBox.Controls.Add($FSOnlyCheckBox)
    $OptionsGroupBox.Controls.Add($ScheckBox)
    $OptionsGroupBox.Controls.Add($MoveCheckBox)
    $OptionsGroupBox.Controls.Add($xfCheckBox)
    $OptionsGroupBox.Controls.Add($xfbox)

    #shows the form
    $Form.Add_Shown({$Form.Activate()})
    [void] $Form.ShowDialog()
}

#Action for donate button
Function Click_Donate
{
    [System.Diagnostics.Process]::Start("https://www.paypal.me/jackofalltech")
}
#action for help button
Function Click_Help
{
    $outputBox.Clear()
    $outputBox.AppendText("CopyTool - V 3.0.0.0`n")
    $outputBox.AppendText("Created By: Kris Gross`n")
    $outputBox.AppendText("Email: Krisgross@sccmtst.com`n")
    $outputBox.AppendText("Twitter: @kmgamd`n")
    $outputBox.AppendText("Updates can be found at: http://www.sccmtst.com/p/tool-downloads.html`n")
    $outputBox.AppendText("This version of CopyTool uses robocopy to copy files and folders.`n")
    $outputBox.AppendText("How To Use:`n")
    $outputBox.AppendText("`n")
    $outputBox.AppendText("1. Browse to or type the path to the content you want to copy or move`n")
    $outputBox.AppendText("`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("`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("`n")
    $outputBox.AppendText("4. Click Start to start the copy process`n")
}
#action for Browse for Source 
Function Click_BrowseSource
{
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null     
    $SourceForm = New-Object System.Windows.Forms.FolderBrowserDialog
    $SourceForm.Rootfolder = "Desktop"
    $SourceForm.Description = "Select Folder"
    [void]$SourceForm.ShowDialog()
    $SourceForm.SelectedPath
    $Form.Dispose()
    $Form.Close()
    $Source = $SourceForm.SelectedPath
    Generate-Form
}
#action for Browse for destination
Function Click_BrowseDestination
{
    [CmdletBinding()]
    param([string]$Description="Select Folder",[string]$RootFolder="Desktop")
    [System.Reflection.Assembly]::LoadWithPartialName("System.windows.forms") | Out-Null     
    $destinationForm = New-Object System.Windows.Forms.FolderBrowserDialog
    $destinationForm.Rootfolder = $RootFolder
    $destinationForm.Description = $Description
    [void]$destinationForm.ShowDialog()
    $destinationForm.SelectedPath
    $Form.Dispose()
    $Form.Close()
    $Destination = $DestinationForm.SelectedPath
    Generate-Form
}
#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
    $outputBox.Clear()
    #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")}
}

Generate-Form 

Popular Posts

Office 365 Deployment - Office 365 Upgrade Task Sequence

SCCM Task Sequence with GUI - How to install more then one image with a single Task Sequence

Windows 10 Setup Script - V 2.0.0.0