# encoding: ascii
# api: powershell
# title: Copy-ItemGUI
# description: Allows you to copy items and display the native windows copy dialogue instead of having to use -passthru or fuss with write-progress
# version: 1.0
# type: function
# author: Nathan Kasco
# license: CC0
# function: Copy-ItemGUI
# x-poshcode-id: 6197
# x-archived: 2016-05-17T10:51:01
# x-published: 2016-01-31T01:54:00
#
#
function Copy-ItemGUI
{
<#
.Synopsis
   GUI display for copy-item function
.DESCRIPTION
   Allows you to copy items and display the native windows copy dialogue instead of having to use -passthru or fuss with write-progress
.EXAMPLE
   Copy-ItemGUI -Source $Folder -Destination "C:\SomeFolder"
.NOTES
   v1.0 - 2016-01-30 - Nathan Kasco
#>
    Param
    (
        [Parameter(Mandatory=$true, ValueFromPipelineByPropertyName=$true, Position=0)]
        $Source,

        [Parameter(Mandatory=$true, Position=1)]
        [string]
        $Destination
    )

    #If destination does not exist, break
    #TODO: Create folder if destination does not exist
    if(!(Test-Path $Destination)){
        break
    }

    $src = gci $Source

    $objShell = New-Object -ComObject "Shell.Application"

    $objFolder = $objShell.NameSpace($Destination) 

    $counter = ($src.Length) - 1
    foreach($file in $src){
        Write-Host -ForegroundColor Cyan "Copying file '"$file.name"' to ' $Destination '"

        try{
            #Info regarding options for displayed info during shell copy - https://technet.microsoft.com/en-us/library/ee176633.aspx
            $objFolder.CopyHere("C:\users\nate\desktop\test\$file", "&H0&")
        }
        catch{
            Write-Error $_
        }

        Write-Host -ForegroundColor Green "Copy complete - Number of items remaining: $counter`n"
        $counter--
    }
}
